A background component that displays a fireworks animation.
Installation
Usage
import { FireworksBackground } from '@/components/animate-ui/backgrounds/fireworks';
export function Hero() {
return (
<section className="relative h-[480px] overflow-hidden">
<FireworksBackground className="absolute inset-0" />
</section>
);
}Examples
Fireworks Circle
Animation
- Rockets launch from the bottom edge every 300 to 800ms (divided by
population), trail upwards and burst into 50 to 150 particles that slow down, fall and fade. - A click launches a rocket towards the pointer.
- The show takes place in a space as wide as the window, with the container's aspect ratio, scaled down to the container: in a container narrower than the window, rockets and particles are smaller and slower. The canvas is drawn at the device pixel ratio.
- The simulation advances one step per displayed frame, so it runs faster on 120Hz screens.
- It pauses off screen and while the tab is hidden: nothing launches and the last frame stays.
- Under reduced motion, it shows a still frame of three bursts and clicks do nothing.
API Reference
FireworksBackground
| Prop | Type | Default |
|---|---|---|
population? | number | 1 |
color? | string | string[] | a random hue per rocket |
fireworkSpeed? | number | { min: number; max: number } | { min: 4, max: 8 } |
fireworkSize? | number | { min: number; max: number } | { min: 2, max: 5 } |
particleSpeed? | number | { min: number; max: number } | { min: 2, max: 7 } |
particleSize? | number | { min: number; max: number } | { min: 1, max: 5 } |
canvasProps? | React.ComponentProps<'canvas'> | - |
...props? | Omit<React.ComponentProps<'div'>, 'color'> | - |
Credits
- Credits to Matt Cannon for the inspiration