黑色背景點擊任意處,多色煙花粒子向四周擴散、重力下墜、逐漸消失,極具視覺衝擊。

<body bgcolor="#000000">
<!-- 14 個預建 Layer/DIV 作為粒子容器 -->
<LAYER name="a0" bgcolor="#ffffff" ...></LAYER> ...
<div id="starsDiv">... 內含多個小 div 粒子 ...</div>
<script>
// Clrs 顏色陣列、sClrs 二次爆發顏色
// Fireworks() 主循環:三角函數計算極座標軌跡
// currStep 控制階段:上升(0-90)→爆發(90-220)→重置
// setTimeout 遞迴驅動
</script>
</body>
x = Mleft + R*cos(θ)*sin(φ), y = Mtop + R*sin(θ)*sin(φ) 模擬球面爆發currStep 從 -10 遞增至 220,<90 為上升同色,>90 為爆發隨機色(Mtop, Mleft) 並換色const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
const fireworks = [];
const particles = [];
canvas.addEventListener('click', e => {
fireworks.push(new Firework(e.clientX, e.clientY));
});
function animate() {
ctx.fillStyle = 'rgba(0,0,0,0.2)'; // 殘影效果
ctx.fillRect(0,0,w,h);
fireworks.forEach((f,i)=>{ f.update(); if(f.dead) fireworks.splice(i,1); });
particles.forEach((p,i)=>{ p.update(); if(p.dead) particles.splice(i,1); });
requestAnimationFrame(animate);
}
animate();
new Audio('firework.mp3').play()touchstart