An interactive background featuring animated dots of varying sizes and speeds, simulating a dynamic and immersive starry space effect.
Installation
Usage
<script setup lang="ts">
import StarsBackground from '@/components/animate-ui/backgrounds/stars/StarsBackground.vue';
</script>
<template>
<section class="relative h-[480px] overflow-hidden">
<StarsBackground class="absolute inset-0" />
</section>
</template>Animation
- Three layers of stars (1, 2 and 3px) scroll upwards in a loop at different speeds, for depth: the smallest crosses 2000px in
speedseconds, the others take two and three times longer. They move with hardware-acceleratedtransforms. - The sky shifts away from the mouse on a spring (
factor,transition), relative to the center of the container, for parallax. On touch screens, a tap shifts it too. - The loops pause off screen and while the tab is hidden.
- Under reduced motion, the stars hold still and there is no parallax.
API Reference
StarsBackground
| Prop | Type | Default |
|---|---|---|
factor? | number | 0.05 |
speed? | number | 50 |
transition? | SpringOptions | { stiffness: 50, damping: 20 } |
star-color? | string | '#fff' |
pointer-events? | boolean | true |
...attrs? | HTMLAttributes | - |
Credits
- Credits to umangladani for the inspiration