原生js实现动态螺纹旋转交互旋转canvas动画效果代码
代码语言:html
所属分类:动画
代码描述:原生js实现动态螺纹旋转交互旋转canvas动画效果代码
代码标签: 动态 螺纹 旋转 交互 旋转 canvas 动画 效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body, html { position: absolute; margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #000; touch-action: none; } canvas { position: absolute; width: 100%; height: 100%; background: hsl(193, 86%, 10%); cursor: crosshair; } </style> </head> <body translate="no" > <canvas></canvas> <script> "use strict"; // adapted from http://fluid.nl/content/designengaged/index.htm /////////////////////////////////////////////////////////// const canvas = { init() { this.elem = document.querySelector("canvas"); this.resize(); window.addEventListener("resize", () => this.resize(), false); return this.elem.getContext("2d"); }, resize() { this.width = this.elem.width = this.elem.offsetWidth; this.height = this.elem.height = this.elem.offsetHeight; this.centerX = this.width / 2; this.centerY = this.height / 2; this.size = 1.25 * Math.sqrt(this.width * this.width + this.height * this.height); }, clear() { ctx.clearRect(0, 0, this.width, this.height); } }; /////////////////////////////////////////////////////////// const pointer = { x: 0, y: 0, init(x, y) { window.addEventListener("pointermove", e => this.move(e), false); this.x = canvas.centerX; this.y = can.........完整代码请登录后点击上方下载按钮下载查看
网友评论0