I have a component that fetches list of items from server and then display that list using *ngFor in template.
I want the list to be displayed with some animation, but one after other. I mean each list item should animate in after other.
I am trying something like this:
import { Component, Input, trigger, state, animate, transition, style } from '@angular/core';
@Component({
selector: 'list-item',
template: ` <li @flyInOut="'in'">{{item}}</li>`,
animations: [
trigger('flyInOut', [
state('in', style({ transform: 'translateX(0)' })),
transition('void => *', [
style({ transform: 'translateX(-100%)' }),
animate(100)
]),
transition('* => void', [
animate(100, style({ transform: 'translateX(100%)' }))
])
])
]
})
export class ListItemComponent {
@Input() item: any;
}
and in my list component template I am using it like:
<ul>
<li *ngFor="let item of list;">
<list-item [item]="item"></list-item>
</li>
</ul>
What it does is displays whole list at once. I want items to enter one by one with some animation.
To use the angular2 animations I set a state property to the iterated item and then just setup a toggle function for the mouseover and mouseout functions. This way each item encapsulated it's animated state and then I could change it as needed
what you want, of the time between each item in the list, see this code. change the file .css to .scss
like this https://codepen.io/jhenriquez856/pen/baPagq
I couldn't find
stagger
support onngFor
in the documentation, but there's nowanimation.done
events
, which can be used to makestaggering ngFor
see@PLUNKER