A lightweight and customizable animate-on-scroll library for Svelte applications. Add beautiful scroll animations to your components with ease.
npm install svelte-animate-on-scroll
<script>
import { AOS } from 'svelte-animate-on-scroll';
</script>
<AOS animate="fade-up">
<h1>This will fade up on scroll</h1>
</AOS>
Prop | Type | Default | Description |
---|---|---|---|
animate | string | required | Animation type to apply. See Available Animations |
ease | string | 'ease-in-out' | Easing function to use. See Available Easings |
delay | number | 0 | Delay before animation starts (in milliseconds) |
duration | number | 300 | Duration of the animation (in milliseconds) |
distance | string | '100px' | Distance for translate animations |
once | boolean | true | Whether animation should only happen once |
top | number | 0 | Offset from top of viewport before triggering |
bottom | number | 0 | Offset from bottom of viewport before triggering |
class | object | { container: '', animate: '' } | Custom classes for container and animated elements |
onupdate | function | (observing) => {} | Callback when visibility changes |
Fade animations:
Zoom animations:
Slide animations:
Flip animations:
<!-- Basic usage -->
<AOS animate="fade-up">
<div>Content that fades up</div>
</AOS>
<!-- With custom options -->
<AOS
animate="zoom-in"
ease="ease-out-back"
delay={200}
duration={600}
distance="50px"
once={false}
>
<div>Content that zooms in repeatedly</div>
</AOS>
<!-- With custom classes -->
<AOS
animate="slide-left"
class={{
container: 'my-container-class',
animate: 'my-animation-class'
}}
>
<div>Content that slides from the left</div>
</AOS>
<!-- With visibility callback -->
<AOS
animate="flip-up"
onupdate={(visible) => {
console.log('Element is visible:', visible);
}}
>
<div>Content that flips up</div>
</AOS>
The library uses the IntersectionObserver API with a fallback to getBoundingClientRect for older browsers. No additional polyfills are required for modern browsers.
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License