Overview
Svelte Atoms Core provides powerful animation lifecycle hooks that work seamlessly with third-party animation libraries like GSAP, Motion One, and anime.js. Every atom exposes hooks for initial state, enter/exit transitions, and data-driven animations.All animation hooks expose the host element, making it easy to integrate with any animation library of your choice.
Animation Hooks API
Every atom component supports these animation lifecycle hooks:Hook Execution Order
initial: Called before the element enters the DOMenter: Called when the element enters the DOManimate: Called when reactive data changes (after enter completes)exit: Called when the element exits the DOM
Using Animation Hooks
Basic Enter/Exit Transitions
Use Svelte’s built-in transitions:Initial State Setup
Set the initial appearance before the enter animation:Data-Driven Animations
Use theanimate hook to respond to state changes:
Integration with Animation Libraries
Motion One
Motion One provides a modern, performant animation API:GSAP
GSAP is the industry-standard animation library:Anime.js
Real-World Examples
Accordion with Smooth Transitions
Toast Notifications
List with Stagger Animation
Page Transitions
Advanced Patterns
Conditional Animations
Animate differently based on conditions:Respecting Reduced Motion
Cleanup and Cancellation
Animation Best Practices
Keep Animations Short
Keep Animations Short
Most UI animations should be between 200-400ms. Longer animations feel sluggish.
Use Appropriate Easing
Use Appropriate Easing
- Ease-out: For elements entering (starts fast, ends slow)
- Ease-in: For elements exiting (starts slow, ends fast)
- Ease-in-out: For elements moving between states
Respect User Preferences
Respect User Preferences
Always check for
prefers-reduced-motion and provide instant or minimal animations for users who need them.Animate Performant Properties
Animate Performant Properties
Prefer animating
transform and opacity over properties like width, height, or top.Next Steps
Composition
Learn component composition patterns
Styling
Explore styling approaches
Components
Browse all animatable components
Motion One Docs
Read the Motion One documentation