大数跨境
0
0

炫酷环形圈(可复制源代码)

炫酷环形圈(可复制源代码) 趣聊科技圈
2024-09-22
1

效果演示

html 代码

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Enhanced Canvas Animation</title>
  <style>
    htmlbody { margin0padding0width100%height100%backgroundradial-gradient(circle, #000000, #131862, #1c1c5c); background-size300% 300%animation: gradientBG 15s ease infinite; }
    canvas { display: block; }
    @keyframes gradientBG { 0% { background-position0% 0%; } 50% { background-position100% 100%; } 100% { background-position0% 0%; } }
  
</style>
</head>
<body>
  <canvas></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
  <script>
    const c = document.querySelector('canvas'); const ctx = c.getContext('2d'); let cw = c.width = innerWidth; let ch = c.height = innerHeight; const ticks = 200const ring1 = []; const ring2 = []; const particles = []; const dur = 14;
    for (let i = 0; i < ticks; i++) { const angle = i / ticks * Math.PI * 2const radius = 270; ring1[i] = { x10x20y10y20lineWidth8a: angle, r: radius, h180 + gsap.utils.wrapYoyo(050, i / ticks * 180), glow15 }; ring2[i] = { x10x20y10y20lineWidth3a: angle, r: radius / 2h180 + gsap.utils.wrapYoyo(060, i / ticks * 180), glow8 }; }
    function createParticles(for (let i = 0; i < 300; i++) { particles.push({ xMath.random() * cw, yMath.random() * ch, sizeMath.random() * 2 + 1alphaMath.random() * 0.5 + 0.5speedMath.random() * 0.5 + 0.5 }); } }
    createParticles();
    const tl = gsap.timeline({ onUpdate: update }).fromTo([ring1, ring2], { x1(i, t) => Math.cos(t.a) * t.r * -1.5y1(i, t) => Math.sin(t.a) * t.r * -1.5x2(i, t) => Math.cos(t.a) * t.r * 1.5y2(i, t) => Math.sin(t.a) * t.r * 1.5 }, { x1(i, t) => Math.cos(t.a) * t.r * 0.3y1(i, t) => Math.sin(t.a) * t.r * 0.3x2(i, t) => Math.cos(t.a) * t.r * 0.15y2(i, t) => Math.sin(t.a) * t.r * 0.15duration: dur / 2ease'power4'repeat-1yoyotrue }, 0).to(ring1, { lineWidth1h'+=150'glow'+=25'duration: dur * 0.25ease'power4.inOut'yoyoEase'power2.in'stagger: { amount: dur, from0repeat-1yoyotrue } }, 0).play(dur * 1.2);
    function drawPath(t{ ctx.strokeStyle = 'hsl(' + t.h + ',100%,50%)'; ctx.lineCap = "round"; ctx.lineWidth = t.lineWidth; ctx.setLineDash([t.lineWidth * 240]); ctx.shadowBlur = t.glow; ctx.shadowColor = ctx.strokeStyle; ctx.beginPath(); ctx.moveTo(t.x1 + cw / 2, t.y1 + ch / 2); ctx.lineTo(t.x2 + cw / 2, t.y2 + ch / 2); ctx.stroke(); }
    function drawParticles({ particles.forEach(p => { ctx.fillStyle = 'rgba(255, 255, 255,' + p.alpha + ')'; ctx.beginPath(); ctx.arc(p.x, p.y, p.size, 0Math.PI * 2); ctx.fill(); p.y -= p.speed; if (p.y < 0) p.y = ch; }); }
    function update({ ctx.clearRect(00, cw, ch); ring1.forEach(drawPath); ring2.forEach(drawPath); drawParticles(); }
    window.onresize = () => { cw = c.width = innerWidth; ch = c.height = innerHeight; update(); };
    window.onpointerup = () => { gsap.to(tl, { duration1ease'power3'timeScale: (tl.isActive() ? 0 : 1) }); };
  
</script>
</body>
</html>


【声明】内容源于网络
0
0
趣聊科技圈
🧐探索科技,发现乐趣。🤩带你玩遍科技好物!
内容 511
粉丝 0
趣聊科技圈 🧐探索科技,发现乐趣。🤩带你玩遍科技好物!
总阅读63
粉丝0
内容511