StealThis .dev

Confetti Explosion

Canvas-based confetti explosion triggered by button click with colorful particles, gravity, rotation, and fade-out effects.

Open in Lab
css javascript canvas vue svelte
Targets: TS JS HTML React Vue Svelte

Code

Confetti Explosion

A satisfying canvas-based confetti explosion that fires colorful particles on button click. Particles exhibit realistic gravity, spin, air resistance, and gentle fade-out.

How it works

  1. Clicking the button spawns a burst of particles at the button’s center
  2. Each particle gets a random velocity, color, size, rotation speed, and shape
  3. A requestAnimationFrame loop applies gravity, drag, and rotation every frame
  4. Particles fade out over time and are removed once fully transparent

Customization

  • Adjust PARTICLE_COUNT, GRAVITY, DRAG, and COLORS in the script
  • Change particle shapes (rectangles, circles, or confetti strips)
  • Modify spread angle and initial velocity for different burst patterns

When to use it

  • Success / completion celebrations
  • Game win screens
  • Form submission confirmations
  • Any moment that deserves a little joy