返回 html-ppt-skill
shockwave.js
根目录 / assets / animations / fx / shockwave.js
1 (function(){
2 window.HPX = window.HPX || {};
3 window.HPX['shockwave'] = function(el){
4 const U = window.HPX._u;
5 const k = U.canvas(el), ctx = k.ctx;
6 const ac = U.accent(el,'#7c5cff'), ac2 = U.accent2(el,'#22d3ee');
7 let waves = [];
8 let last = -1;
9 const stop = U.loop((t) => {
10 ctx.fillStyle = 'rgba(0,0,0,0.12)';
11 ctx.fillRect(0,0,k.w,k.h);
12 if (t - last > 0.6){ last = t; waves.push({t:0}); }
13 const cx=k.w/2, cy=k.h/2;
14 const max = Math.hypot(k.w,k.h)/2;
15 waves = waves.filter(w => w.t < 1);
16 for (const w of waves){
17 w.t += 0.012;
18 const r = w.t * max;
19 const alpha = 1 - w.t;
20 ctx.strokeStyle = w.t<0.5?ac2:ac;
21 ctx.globalAlpha = alpha;
22 ctx.lineWidth = 3 + (1-w.t)*3;
23 ctx.beginPath(); ctx.arc(cx,cy,r,0,Math.PI*2); ctx.stroke();
24 ctx.strokeStyle = '#fff';
25 ctx.lineWidth = 1;
26 ctx.globalAlpha = alpha*0.4;
27 ctx.beginPath(); ctx.arc(cx,cy,r*0.92,0,Math.PI*2); ctx.stroke();
28 }
29 ctx.globalAlpha = 1;
30 // core
31 const g = ctx.createRadialGradient(cx,cy,0,cx,cy,40);
32 g.addColorStop(0,'rgba(255,255,255,0.9)');
33 g.addColorStop(1,'rgba(124,92,255,0)');
34 ctx.fillStyle = g;
35 ctx.beginPath(); ctx.arc(cx,cy,40,0,Math.PI*2); ctx.fill();
36 });
37 return { stop(){ stop(); k.destroy(); } };
38 };
39 })();
40
40 lines JAVASCRIPT