Svelte Animate is a lightweight, accessible Svelte component that wraps Animate.css, simplifying animation integration in Svelte applications. It offers advanced features like: Sequential animation effects, Configurable trigger modes (hover, click, auto), Accessibility-first design, Reduced motion support, Flexible repeat and timing controls. Designed for Svelte's latest features, it provides more sophisticated animation capabilities than standard Svelte transitions.
npm install -D svelte-animate
# or
pnpm install -D svelte-animate
# or
yarn add -D svelte-animate
import {Animate} from 'svelte-animate';
<Animate>
<div>This will bounce on hover!</div>
</Animate>
<Animate animations="fadeIn" trigger="click" duration={2000} delay={1000} repeat="2">
<div>Click me for a customized animation experience!</div>
</Animate>
<Animate
animations={[
{ action: 'fadeIn', duration: 1000, delay: 500 },
{ action: 'zoomOut', duration: 2000, pause: 1000 }
]}
trigger="click"
hideBetween={true}
hideEnd={true}
showReplayButton={true}
>
<div>Click me for a customized animation sequence!</div>
</Animate>
Prop | Type | Default | Description |
---|---|---|---|
children |
Snippet |
Required | The content to be animated |
animations |
AnimationConfig[] | AnimationType[] | AnimationType |
'bounce' |
The animation effects to apply |
trigger |
'hover' | 'click' | 'both' | 'auto' |
'hover' |
What triggers the animation |
duration |
number |
1000 |
Default animation duration (ms) |
hideBetween |
boolean |
false |
Whether to hide element between animations |
hideEnd |
boolean |
false |
Whether to hide element after animation sequence |
delay |
number |
0 |
Default delay before animations start (ms) |
repeat |
'1' | '2' | '3' | 'infinite' |
'1' |
Number of times to repeat the animation |
pauseDuration |
number |
0 |
Default pause between animations (ms) |
class |
string |
'' |
Additional CSS classes for the container |
debug |
boolean |
false |
Enable debug mode with visible status updates |
showReplayButton |
boolean |
false |
Show replay button after animation ends |
When using the animations
prop with detailed configuration:
interface AnimationConfig {
action: AnimationType; // The animation effect to apply
duration?: number; // Duration for this specific animation
delay?: number; // Delay before this animation starts
pause?: number; // Pause after this animation
}
<Animate>
<button>Hover to bounce!</button>
</Animate>
<Animate animations="rubberBand" trigger="click" delay={2000} duration={1000}>
<div>Click for a delayed effect!</div>
</Animate>
<Animate
animations={[
{ action: 'fadeIn', duration: 1000 },
{ action: 'pulse', duration: 500, pause: 1000 },
{ action: 'fadeOut', duration: 1000 }
]}
trigger="both"
repeat="3"
showReplayButton={true}
>
<span>Complex animation sequence!</span>
</Animate>
<Animate animations="bounce" trigger="click" debug={true}>
<div>Watch the debug info in the corner!</div>
</Animate>
Supports all modern browsers that support:
Contributions are welcome! Please feel free to submit a Pull Request. When contributing, please:
MIT
This component is powered by Animate.css.