A background component featuring an interactive gravity stars effect.
Installation
Usage
<script setup lang="ts">
import GravityStarsBackground from '@/components/animate-ui/backgrounds/gravity-stars/GravityStarsBackground.vue';
</script>
<template>
<section class="relative h-[480px] overflow-hidden">
<GravityStarsBackground class="absolute inset-0" />
</section>
</template>Animation
- Stars drift across a canvas at
movement-speed, slow down little by little, wrap around its edges and glow. - Near the pointer (
mouse-influence), they are pulled in or pushed away (mouse-gravity) 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 |
|---|---|---|
stars-count? | number | 75 |
stars-size? | number | 2 |
stars-opacity? | number | 0.75 |
glow-intensity? | number | 15 |
glow-animation? | 'instant' | 'ease' | 'spring' | 'ease' |
movement-speed? | number | 0.3 |
mouse-influence? | number | 100 |
mouse-gravity? | 'attract' | 'repel' | 'attract' |
gravity-strength? | number | 75 |
stars-interaction? | boolean | false |
stars-interaction-type? | 'bounce' | 'merge' | 'bounce' |
...attrs? | HTMLAttributes | - |
Credits
- Credits to Brett Jackson for the initial Framer component.