For the complete documentation index, see llms.txt. This page is also available as Markdown.

Animation (Comprehensive Guide)

A comprehensive developer guide for implementing animations in Aurelia applications, covering CSS animations, Web Animations API, lifecycle hooks, third-party libraries, and advanced animation pattern

Master animation techniques in Aurelia applications, from simple CSS transitions to complex coordinated animations using lifecycle hooks, modern Web APIs, and third-party libraries.

Overview

Aurelia provides multiple approaches for implementing animations, each suited to different use cases:

Approach
Best For
Complexity
Performance

CSS Transitions

Simple state changes, hover effects

Low

Excellent

CSS Animations

Loading spinners, attention-grabbers

Low

Excellent

Web Animations API

Programmatic control, complex sequences

Medium

Excellent

Lifecycle Hooks

Component mount/unmount, route transitions

Medium

Excellent

Third-party Libraries

Advanced effects, timelines, physics

High

Good

When to Use What

Choose CSS Transitions When:

  • Animating between two states (expanded/collapsed, visible/hidden)

  • Creating hover effects or focus states

  • You need the best performance with minimal code

Choose CSS Keyframe Animations When:

  • Creating looping animations (spinners, pulsing effects)

  • Needing multi-step animations that don't respond to state

  • Building simple attention-grabbing effects

Choose Web Animations API When:

  • You need JavaScript control over CSS-quality animations

  • Building interactive animations that respond to user input

  • Coordinating multiple animations programmatically

  • Animations need to be paused, reversed, or dynamically adjusted

Choose Lifecycle Hooks When:

  • Animating component entrance/exit

  • Coordinating animations with component lifecycle

  • Creating route transition effects

  • Animations depend on DOM measurements

Choose Third-party Libraries When:

  • You need advanced easing functions or physics

  • Building complex animation timelines

  • Implementing scroll-triggered animations

  • Need SVG morphing or path animations

CSS-Based Animations

Simple State Transitions

CSS transitions are perfect for smooth state changes:

Multi-Step Keyframe Animations

For more complex animations, use @keyframes:

Staggered List Animations

Animate list items with a stagger effect using CSS custom properties:

Web Animations API

The Web Animations API provides programmatic control over animations with excellent performance.

Basic Web Animations

Interactive Animations

Create animations that respond to user input:

Controllable Animations

Create animations you can pause, play, or reverse:

Coordinated Animations

Run multiple animations simultaneously:

Component Lifecycle Animations

Animate components during their attachment and detachment using lifecycle hooks.

Fade In/Out Animation

Reusable Animation Hooks

Create reusable animation controllers with @lifecycleHooks():

Register globally in your app configuration:

Or use per-component:

Animating Conditional Content

Animate elements controlled by if.bind:

Animating List Items

Animate individual items in a repeat.for:

Router Transition Animations

Animate page transitions using router lifecycle hooks.

Quick Router Animation Example

View Transitions API

The modern View Transitions API provides smooth, cross-fade transitions between DOM states with minimal code.

Basic View Transitions

Customizing View Transitions

Control the transition with CSS:

Named View Transitions

Transition specific elements independently:

Third-Party Animation Libraries

Aurelia works seamlessly with popular animation libraries.

Anime.js Integration

Anime.js provides powerful, lightweight animations:

GSAP Integration

GSAP provides professional-grade animation capabilities:

Stagger Animations with GSAP

Create beautiful staggered animations:

Advanced Patterns

Reusable Animation Composer

Create a library of reusable animations:

Usage in components:

Sequential Animations

Chain animations together in sequence:

Parallel Animation Groups

Run groups of animations simultaneously:

Scroll-Triggered Animations

Animate elements as they enter the viewport:

Performance Optimization

Use GPU-Accelerated Properties

Always prefer properties that can be animated on the GPU:

Hint the Browser with will-change

For complex animations, hint what will change:

Clean Up Animations

Always cancel animations when components are destroyed:

Batch DOM Operations

Minimize layout thrashing by batching DOM reads and writes:

Accessibility Considerations

Respect prefers-reduced-motion

Always respect user preferences for reduced motion:

In JavaScript:

Maintain Focus Management

Ensure focus remains intuitive during animations:

Provide Skip Options

For long or complex animations, provide a way to skip:

Lifecycle Hook Reference

Understanding lifecycle hooks is crucial for timing animations correctly:

Hook
When Called
Best For
Return Promise?

created

After construction

Element reference setup

No

binding

Before data binding

Pre-animation state setup

No

bound

After data binding

Data-dependent setup

No

attaching

Before DOM insertion

Enter animations

Yes

attached

After DOM insertion

Animations needing measurements

No

detaching

Before DOM removal

Exit animations

Yes

unbinding

Before unbinding

Cleanup

No

disposing

Before disposal

Cancel active animations

No

Best Practices for Lifecycle Animations

  1. Always return promises from attaching and detaching:

  2. Handle interruptions - Cancel animations if detached early:

  3. Coordinate complex animations:

Real-World Examples

Notification Toast

Summary

Aurelia provides a flexible animation system that works with:

  • CSS for simple, performant animations

  • Web Animations API for programmatic control

  • Lifecycle hooks for component and route transitions

  • Third-party libraries for advanced effects

Choose the right tool for your needs, prioritize performance, and always consider accessibility.

Last updated

Was this helpful?