Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
按住鼠标左键跟随光标
css
body { margin: 0; padding: 0; overflow: hidden; } div { font-family: Arial; font-size: 12px; position: absolute; text-align: center; width: 100%; bottom: 12px; color: rgba(200, 240, 256, 0.2); }
JavaScript
/* * Same trick, different pony * rinse + repeat */ let conf = { NUM_PARTICLES: 8, NUM_STRANDS: 12, FRAME_RATE: 60 } let pos = {x: Math.random() * window.innerWidth + 1, y:Math.random() * window.innerHeight + 1} function setup() { createCanvas(window.innerWidth, window.innerHeight); frameRate(conf.FRAME_RATE) pos = {x: Math.random() * window.innerWidth + 1, y:Math.random() * window.innerHeight + 1} } class Strand { constructor () { this.p = [] let p = this.p let r = Math.random() * 0.4 this.sr = Math.random(); while(conf.NUM_PARTICLES > p.length) { r = r * 0.2 let particle = new Particle(1 - p.length/conf.NUM_PARTICLES, r) if (p.length > 0) { particle.follow = p[p.length - 1] } p.push(particle) } } draw () { let q1, q2, q3, q4; this.p.map(p => { p.update() }) const sections = {a:[], b:[]} let i; for (i = this.p.length - 1; i >= 0; i--){ noStroke() const pt = this.p[i] if (i === 0 || i === this.p.length - 1) { q1 = [pt.x, pt.y] q2 = [pt.x, pt.y] sections.a.push(q1) //to-end } else { q1 = [ Math.cos(pt.a+HALF_PI)*pt.w + pt.x, Math.sin(pt.a+HALF_PI)*pt.w + pt.y ] q2 = [ Math.cos(pt.a-HALF_PI)*pt.w + pt.x, Math.sin(pt.a-HALF_PI)*pt.w + pt.y ] sections.a.push(q1) //to-end sections.b.unshift(q2) //to-front } if (i < this.p.length-1 && pt.a !== null){ fill( color( Math.sin(a/2000 * TWO_PI + this.sr*TWO_PI) * 45 + 20, Math.sin(a/2000 * TWO_PI + this.sr*TWO_PI) * 12 + pt.c * 0.8, Math.sin(a/2000 * TWO_PI + this.sr) * 95 + 20 + pt.c * 0.6, Math.cos(i/this.p.length * PI) * 250 * 0.1 ) ) quad(q1[0], q1[1], q2[0], q2[1], q3[0], q3[1], q4[0], q4[1]) } q4 = [q1[0], q1[1]] q3 = [q2[0], q2[1]] } let s = sections.a.concat(sections.b) noFill() for (i = 3; i < s.length; i++){ let pts = [...s[i-3], ...s[i-2], ...s[i-1], ...s[i]] stroke( 80 + Math.cos(a/2000 * TWO_PI) * 25, 108 + Math.cos(a/2000 * TWO_PI) * 65, 255, 90 ); curve(...pts) } } } class Particle { constructor(n, r){ try { this.x = mouseX this.y = mouseY } catch (e) { this.x = pos.x this.y = pos.y } this.vx = 0 this.vy = 0 this.c = Math.floor(n * 120 + 120) this.follow = null; this.a = null this.width = 32 this.r = r || Math.random() * 0.04 } update () { if (a % 2 === 0) { if (this.follow !== null){ this.vx = this.vx * (0.68 - this.r / 2) - (this.x - this.follow.x) * (0.08 - this.r*0.2) this.vy = this.vy * (0.68 - this.r / 2) - (this.y - this.follow.y) * (0.08 - this.r*0.2) } else { if(mouseIsPressed){ // on mouse-down, follow mouse this.vx = this.vx * (0.98 - this.r * 0.13) - (this.x - mouseX) * (0.01 + this.r*0.5) this.vy = this.vy * (0.98 - this.r * 0.13) - (this.y - mouseY) * (0.01 + this.r*0.5) } else { this.vx = this.vx * (0.98 - this.r * 0.3) - (this.x - pos.x) * (0.02 + this.r*0.4) this.vy = this.vy * (0.98 - this.r * 0.3) - (this.y - pos.y) * (0.02 + this.r*0.4) } } this.a = Math.atan2(this.vy, this.vx) let len = Math.min(this.vy * this.vy + this.vx * this.vx, 7500) / 3500 len = sin(len * HALF_PI) this.w = this.width * len + 5 } this.vx = this.vx * 0.89 this.vy = this.vy * 0.89 this.x += this.vx / (conf.FRAME_RATE/85) this.y += this.vy / (conf.FRAME_RATE/85) } } window.addEventListener('resize', ()=>setup()) const strands = [] while (strands.length < conf.NUM_STRANDS) { strands.push(new Strand()) } let a = 0 /// every frame ... draw = () => { a = (a + 1) % 2000 if (a % 12 === 0) { // pick a new random location every n frames pos = { x: (Math.random() * 0.5 + 0.25) * window.innerWidth, y: (Math.random() * 0.5 + 0.25) * window.innerHeight } } background( Math.cos(a/2000 * TWO_PI) * 65 + 50, 40, Math.sin(a/2000 * TWO_PI) * 5 + 90, 50 ); strands.forEach(s => s.draw()) }
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>超炫线条跟随效果p5.js-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号