LogoLogo
HomeDiscourseBlogDiscord
  • Introduction
  • Introduction
    • Quick start
    • Aurelia for new developers
    • Hello world
      • Creating your first app
      • Your first component - part 1: the view model
      • Your first component - part 2: the view
      • Running our app
      • Next steps
  • Templates
    • Template Syntax
      • Attribute binding
      • Event binding
      • Text interpolation
      • Template promises
      • Template references
      • Template variables
      • Globals
    • Custom attributes
    • Value converters (pipes)
    • Binding behaviors
    • Form Inputs
    • CSS classes and styling
    • Conditional Rendering
    • List Rendering
    • Lambda Expressions
    • Local templates (inline templates)
    • SVG
  • Components
    • Component basics
    • Component lifecycles
    • Bindable properties
    • Styling components
    • Slotted content
    • Scope and context
    • CustomElement API
    • Template compilation
      • processContent
      • Extending templating syntax
      • Modifying template parsing with AttributePattern
      • Extending binding language
      • Using the template compiler
      • Attribute mapping
  • Getting to know Aurelia
    • Routing
      • @aurelia/router
        • Getting Started
        • Creating Routes
        • Routing Lifecycle
        • Viewports
        • Navigating
        • Route hooks
        • Router animation
        • Route Events
        • Router Tutorial
        • Router Recipes
      • @aurelia/router-lite
        • Getting started
        • Router configuration
        • Configuring routes
        • Viewports
        • Navigating
        • Lifecycle hooks
        • Router hooks
        • Router events
        • Navigation model
        • Transition plan
    • App configuration and startup
    • Enhance
    • Template controllers
    • Understanding synchronous binding
    • Dynamic composition
    • Portalling elements
    • Observation
      • Observing property changes with @observable
      • Effect observation
      • HTML observation
      • Using observerLocator
    • Watching data
    • Dependency injection (DI)
    • App Tasks
    • Task Queue
    • Event Aggregator
  • Developer Guides
    • Animation
    • Testing
      • Overview
      • Testing attributes
      • Testing components
      • Testing value converters
      • Working with the fluent API
      • Stubs, mocks & spies
    • Logging
    • Building plugins
    • Web Components
    • UI virtualization
    • Errors
      • 0001 to 0023
      • 0088 to 0723
      • 0901 to 0908
    • Bundlers
    • Recipes
      • Apollo GraphQL integration
      • Auth0 integration
      • Containerizing Aurelia apps with Docker
      • Cordova/Phonegap integration
      • CSS-in-JS with Emotion
      • DOM style injection
      • Firebase integration
      • Markdown integration
      • Multi root
      • Progress Web Apps (PWA's)
      • Securing an app
      • SignalR integration
      • Strongly-typed templates
      • TailwindCSS integration
      • WebSockets Integration
      • Web Workers Integration
    • Playground
      • Binding & Templating
      • Custom Attributes
        • Binding to Element Size
      • Integration
        • Microsoft FAST
        • Ionic
    • Migrating to Aurelia 2
      • For plugin authors
      • Side-by-side comparison
    • Cheat Sheet
  • Aurelia Packages
    • Validation
      • Validation Tutorial
      • Plugin Configuration
      • Defining & Customizing Rules
      • Architecture
      • Tagging Rules
      • Model Based Validation
      • Validation Controller
      • Validate Binding Behavior
      • Displaying Errors
      • I18n Internationalization
      • Migration Guide & Breaking Changes
    • i18n Internationalization
    • Fetch Client
      • Overview
      • Setup and Configuration
      • Response types
      • Working with forms
      • Intercepting responses & requests
      • Advanced
    • Event Aggregator
    • State
    • Store
      • Configuration and Setup
      • Middleware
    • Dialog
  • Tutorials
    • Building a ChatGPT inspired app
    • Building a realtime cryptocurrency price tracker
    • Building a todo application
    • Building a weather application
    • Building a widget-based dashboard
    • React inside Aurelia
    • Svelte inside Aurelia
    • Synthetic view
    • Vue inside Aurelia
  • Community Contribution
    • Joining the community
    • Code of conduct
    • Contributor guide
    • Building and testing aurelia
    • Writing documentation
    • Translating documentation
Powered by GitBook
On this page
  • Component-based animations
  • Stateful Animations
  • Reactive Animations

Was this helpful?

Export as PDF
  1. Developer Guides

Animation

A developer guide that details numerous strategies for implementing animation into Aurelia applications.

Learn numerous techniques for implementing animations into your Aurelia applications.

Component-based animations

In instances where you don't need to implement router-based transition animations (entering and leaving), we can lean on traditional CSS-based animations to add animation to our Aurelia applications.

Let's animate the disabled state of a button by making it wiggle when we click on it:

export class MyApp {
    private disabled = false;
    
    animateButton() {
        this.disabled = true;
        
        setTimeout(() => {
            this.disabled = false;
        }, 2000);
    }
}
@keyframes wiggle {
  0%, 7% {
    transform: rotateZ(0);
  }
  15% {
    transform: rotateZ(-15deg);
  }
  20% {
    transform: rotateZ(10deg);
  }
  25% {
    transform: rotateZ(-10deg);
  }
  30% {
    transform: rotateZ(6deg);
  }
  35% {
    transform: rotateZ(-4deg);
  }
  40%, 100% {
    transform: rotateZ(0);
  }
}

.wiggle {
  animation: wiggle 2s linear infinite;
}
<button type="button" wiggle.class="disabled" click.trigger="animateButton()">Wiggle!</button>

Stateful Animations

Some animations are reactive based on user input or other application actions. An example might be a mousemove event changing the background colour of an element.

In this example, when the user moves their mouse over the DIV, we get the clientX value and feed it to a reactive style string that uses the x value to complete the HSL color value. We use lower percentages for the other values to keep the background dark for our white text.

export class MyApp {
    private x = 0;
    
    mouseMove(x) {
        this.x = x;
    }
}
.movetransition {
    padding: 20px;
    transition: 0.4s background-color easein-out;
}
<div
  mousemove.trigger="mouseMove($event.clientX)"
  style="background-color: hsl(${x}, 40%, 32%)"
  class="movetransition"
>
  <p>Move it, move it.</p>
  <p>X value is: ${x}</p>
</div>

Reactive Animations

Not to be confused with state animations, a reactive animation is where we respond to changes in our view models instead of views and animate accordingly. You might use an animation library or custom animation code in these instances.

In the following example, we will use the animation engine Anime.js to animate numeric values when a slider input is changed. Using the change event on our range slider, we'll animate the number up and down depending on the dragged value.

import anime from 'animejs';

export class MyApp {
  private sliderVal = 0;
  private sliderWrapper: HTMLElement;

  animateValue() {
    anime({
      targets: this.sliderWrapper,
      textContent: `${this.sliderVal}`,
      easing: 'easeInOutQuad',
      round: true,
      duration: 1200,
    });
  }
}
<input
  type="range"
  min="0"
  max="1000000"
  value.bind="sliderVal"
  change.trigger="animateValue()"
/>

<p ref="sliderWrapper" class="slider-wrapper">${sliderVal & oneTime}</p>
.slider-wrapper {
  background: #333;
  color: #fff;
  display: block;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 19px;
  font-weight: bold;
  padding: 12px;
}
PreviousEvent AggregatorNextTesting

Last updated 2 years ago

Was this helpful?

LogoAurelia Wiggle Animation - StackBlitzStackBlitz
LogoAurelia Stateful Animation - StackBlitzStackBlitz
LogoAurelia Reactive Animation - StackBlitzStackBlitz