A background component featuring an interactive gravity stars effect.
Installation
Usage
import { GravityStarsBackground } from '@/components/animate-ui/backgrounds/gravity-stars';
export function Hero() {
return (
<section className="relative h-[480px] overflow-hidden">
<GravityStarsBackground className="absolute inset-0" />
</section>
);
}Animation
- Stars drift across a canvas at
movementSpeed, slow down little by little, wrap around its edges and glow. - Near the pointer (
mouseInfluence), they are pulled in or pushed away (mouseGravity) and glow brighter. The pointer's last position keeps acting after it leaves (before the first move, it is the top-left corner). - The stars take the text color (
currentColor), so they follow light and dark mode. - The canvas is sized to its container at the device pixel ratio. A resize scatters the stars again.
- 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.
- Under reduced motion, the stars hold still.
API Reference
GravityStarsBackground
| Prop | Type | Default |
|---|---|---|
starsCount? | number | 75 |
starsSize? | number | 2 |
starsOpacity? | number | 0.75 |
glowIntensity? | number | 15 |
glowAnimation? | 'instant' | 'ease' | 'spring' | 'ease' |
movementSpeed? | number | 0.3 |
mouseInfluence? | number | 100 |
mouseGravity? | 'attract' | 'repel' | 'attract' |
gravityStrength? | number | 75 |
starsInteraction? | boolean | false |
starsInteractionType? | 'bounce' | 'merge' | 'bounce' |
...props? | React.ComponentProps<'div'> | - |
Credits
- Credits to Brett Jackson for the initial Framer component.