Changed around line 1
+ class Confetti {
+ constructor() {
+ this.particles = [];
+ this.running = false;
+ this.lastScroll = window.scrollY;
+ this.init();
+ }
+
+ init() {
+ document.addEventListener('click', (e) => this.createBurst(e.clientX, e.clientY));
+ document.addEventListener('scroll', () => this.handleScroll());
+ document.getElementById('confettiButton').addEventListener('click', (e) => {
+ e.stopPropagation();
+ this.createBurst(window.innerWidth / 2, window.innerHeight / 2, 100);
+ });
+ this.animate();
+ }
+
+ handleScroll() {
+ const currentScroll = window.scrollY;
+ const diff = Math.abs(currentScroll - this.lastScroll);
+ if (diff > 20) {
+ this.createBurst(
+ Math.random() * window.innerWidth,
+ Math.random() * window.innerHeight,
+ diff / 2
+ );
+ this.lastScroll = currentScroll;
+ }
+ }
+
+ createParticle(x, y) {
+ return {
+ x,
+ y,
+ color: `hsl(${Math.random() * 360}, 80%, 60%)`,
+ size: Math.random() * 6 + 4,
+ speedX: Math.random() * 12 - 6,
+ speedY: Math.random() * -15 - 5,
+ rotation: Math.random() * 360,
+ rotationSpeed: (Math.random() - 0.5) * 10,
+ gravity: 0.5,
+ opacity: 1,
+ life: 1,
+ decay: Math.random() * 0.02 + 0.02
+ };
+ }
+
+ createBurst(x, y, amount = 30) {
+ for (let i = 0; i < amount; i++) {
+ this.particles.push(this.createParticle(x, y));
+ }
+ }
+
+ animate() {
+ const canvas = document.createElement('canvas');
+ const ctx = canvas.getContext('2d');
+ document.body.appendChild(canvas);
+ canvas.style.position = 'fixed';
+ canvas.style.top = '0';
+ canvas.style.left = '0';
+ canvas.style.pointerEvents = 'none';
+ canvas.style.zIndex = '1000';
+
+ const resize = () => {
+ canvas.width = window.innerWidth;
+ canvas.height = window.innerHeight;
+ };
+ window.addEventListener('resize', resize);
+ resize();
+
+ const loop = () => {
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ this.particles.forEach((p, index) => {
+ p.x += p.speedX;
+ p.y += p.speedY;
+ p.speedY += p.gravity;
+ p.rotation += p.rotationSpeed;
+ p.life -= p.decay;
+ p.opacity = p.life;
+
+ ctx.save();
+ ctx.translate(p.x, p.y);
+ ctx.rotate((p.rotation * Math.PI) / 180);
+ ctx.globalAlpha = p.opacity;
+ ctx.fillStyle = p.color;
+ ctx.fillRect(-p.size / 2, -p.size / 2, p.size, p.size);
+ ctx.restore();
+ });
+
+ this.particles = this.particles.filter(p => p.life > 0);
+ requestAnimationFrame(loop);
+ };
+ loop();
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => new Confetti());