Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body, html { margin: 0px; padding: 0px; position: fixed; background: rgb(30, 30, 30); cursor: none; }
JavaScript
window.onload = function () { //functions definition //class definition class segm { constructor(x, y, l) { this.b = Math.random() * 1.9 + 0.1; this.x0 = x; this.y0 = y; this.a = Math.random() * 2 * Math.PI; this.x1 = this.x0 + l * Math.cos(this.a); this.y1 = this.y0 + l * Math.sin(this.a); this.l = l; } update(x, y) { this.x0 = x; this.y0 = y; this.a = Math.atan2(this.y1 - this.y0, this.x1 - this.x0); this.x1 = this.x0 + this.l * Math.cos(this.a); this.y1 = this.y0 + this.l * Math.sin(this.a); } } class rope { constructor(tx, ty, l, b, slq, typ) { if (typ == "l") { this.res = l / 2; } else { this.res = l / slq; } this.type = typ; this.l = l; this.segm = []; this.segm.push(new segm(tx, ty, this.l / this.res)); for (let i = 1; i < this.res; i++) { this.segm.push( new segm(this.segm[i - 1].x1, this.segm[i - 1].y1, this.l / this.res) ); } this.b = b; } update(t) { this.segm[0].update(t.x, t.y); for (let i = 1; i < this.res; i++) { this.segm[i].update(this.segm[i - 1].x1, this.segm[i - 1].y1); } } show() { if (this.type == "l") { c.beginPath(); for (let i = 0; i < this.segm.length; i++) { c.lineTo(this.segm[i].x0, this.segm[i].y0); } c.lineTo( this.segm[this.segm.length - 1].x1, this.segm[this.segm.length - 1].y1 ); c.strokeStyle = "white"; c.lineWidth = this.b; c.stroke(); c.beginPath(); c.arc(this.segm[0].x0, this.segm[0].y0, 1, 0, 2 * Math.PI); c.fillStyle = "white"; c.fill(); c.beginPath(); c.arc( this.segm[this.segm.length - 1].x1, this.segm[this.segm.length - 1].y1, 2, 0, 2 * Math.PI ); c.fillStyle = "white"; c.fill(); } else { for (let i = 0; i < this.segm.length; i++) { c.beginPath(); c.arc( this.segm[i].x0, this.segm[i].y0, this.segm[i].b, 0, 2 * Math.PI ); c.fillStyle = "white"; c.fill(); } c.beginPath(); c.arc( this.segm[this.segm.length - 1].x1, this.segm[this.segm.length - 1].y1, 2, 0, 2 * Math.PI ); c.fillStyle = "white"; c.fill(); } } } //setting up canvas let c = init("canvas").c, canvas = init("canvas").canvas, w = (canvas.width = window.innerWidth), h = (canvas.height = window.innerHeight), ropes = []; //variables definition let nameOfVariable = "value", mouse = {}, last_mouse = {}, rl = 50, randl = [], target = { x: w / 2, y: h / 2 }, last_target = {}, t = 0, q = 10, da = [], type = "l"; for (let i = 0; i < 100; i++) { if (Math.random() > 0.25) { type = "l"; } else { type = "o"; } ropes.push( new rope( w / 2, h / 2, (Math.random() * 1 + 0.5) * 500, Math.random() * 0.4 + 0.1, Math.random() * 15 + 5, type ) ); randl.push(Math.random() * 2 - 1); da.push(0); } //place for objects in animation function draw() { if (mouse.x) { target.errx = mouse.x - target.x; target.erry = mouse.y - target.y; } else { target.errx = w / 2 + ((h / 2 - q) * Math.sqrt(2) * Math.cos(t)) / (Math.pow(Math.sin(t), 2) + 1) - target.x; target.erry = h / 2 + ((h / 2 - q) * Math.sqrt(2) * Math.cos(t) * Math.sin(t)) / (Math.pow(Math.sin(t), 2) + 1) - target.y; } target.x += target.errx / 10; target.y += target.erry / 10; t += 0.01; for (let i = 0; i < ropes.length; i++) { if (randl[i] > 0) { da[i] += (1 - randl[i]) / 10; } else { da[i] += (-1 - randl[i]) / 10; } ropes[i].update({ x: target.x + randl[i] * rl * Math.cos((i * 2 * Math.PI) / ropes.length + da[i]), y: target.y + randl[i] * rl * Math.sin((i * 2 * Math.PI) / ropes.length + da[i]) }); ropes[i].show(); } last_target.x = target.x; last_target.y = target.y; } //mouse position canvas.addEventListener( "mousemove", function (e) { last_mouse.x = mouse.x; last_mouse.y = mouse.y; mouse.x = e.pageX - this.offsetLeft; mouse.y = e.pageY - this.offsetTop; }, false ); canvas.addEventListener("mouseleave", function (e) { mouse.x = false; mouse.y = false; }); //animation frame function loop() { window.requestAnimFrame(loop); c.clearRect(0, 0, w, h); draw(); } //window resize window.addEventListener("resize", function () { (w = canvas.width = window.innerWidth), (h = canvas.height = window.innerHeight); loop(); }); //animation runner loop(); setInterval(loop, 1000 / 60); };
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>canvas粒子鼠标跟随-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号