Give each piece a random angle and speed to derive an initial velocity (`vx, vy`), then each frame update position with `x += vx`, `y += vy + gravity * t²` — a simple parabolic-motion approximation. Keep incrementing `rotate` too, so pieces appear to tumble as they fall.
Fade `opacity` toward zero proportional to elapsed time, so pieces dissolve naturally before flying off screen. Once a piece's life is over (opacity 0, or a frame count reached), remove it from the DOM — otherwise memory keeps accumulating.
Past 20–30 pieces, the DOM-element approach can start to stutter. If you need frequent, large bursts, move to a `<canvas>`-based library (canvas-confetti and similar) instead.
When to use
Use it once, at a clear moment of success — payment done, onboarding finished, an achievement unlocked. Overuse dilutes the celebration.