This can be done using the Aurelia custom attributes function.
Create a new javascript file to describe the attribute (I named the attribute "animateonchange"):
import {inject, customAttribute} from 'aurelia-framework'; import {CssAnimator} from 'aurelia-animator-css'; @customAttribute('animateonchange') @inject(Element, CssAnimator) export class AnimateOnChangeCustomAttribute { constructor(element, animator) { this.element = element; this.animator = animator; this.initialValueSet = false; } valueChanged(newValue){ if (this.initialValueSet) { this.animator.addClass(this.element, 'background-animation').then(() => { this.animator.removeClass(this.element, 'background-animation'); }); } this.initialValueSet = true; } }
It gets the element and CSS animator in the constructor. When the value changes, it animates the element with the predefined CSS class name. The first change is ignored (no need to animate at boot). Here's how to use this custom item:
<template> <require from="./animateonchange"></require> <div animateonchange.bind="someProperty">${someProperty}</div> </template>
See the full example on my blog or on plunkr
source share