Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 stagger list animation

I am trying to stagger an animation in my app with a dynamic list. I would like to animation enter and leave if possible but would settle just to get the on enter to work.

animations: [
    trigger('slideIn', [
        transition(':enter', [
            style({
                transform: 'translate3d(0,-10px,0)',
                opacity: 0
            }),
            animate('0.1s', style({
                transform: 'translate3d(0,0,0)',
                opacity: 1
            }))
        ])
    ])  
  ]

Above is the animation code that I cannot get to run and below is how I implemented it into the template.

<ion-content [@listAnimation]="eventsList?.length">
    <ion-list>
              <event-item *ngFor="let item of eventsList" [item]="item"></event-item>
    </ion-list>
     <empty-list [list]="eventsList" [message]="'There are no event items to display.'"></empty-list>
    <ion-infinite-scroll [enabled]="infiniteScroll === null" (ionInfinite)="doInfinite($event)">
        <ion-infinite-scroll-content></ion-infinite-scroll-content>
     </ion-infinite-scroll>
</ion-content>

Please let me know where I have gone wrong.

like image 652
Ross Rawlins Avatar asked Dec 15 '17 13:12

Ross Rawlins


People also ask

What is stagger animation?

A staggered animation consists of sequential or overlapping animations. To create a staggered animation, use multiple Animation objects. One AnimationController controls all of the Animation s. Each Animation object specifies the animation during an Interval . For each property being animated, create a Tween .

What is the use of animateChild () function in angular?

Each time an animation is triggered in Angular, the parent animation always gets priority and child animations are blocked. For a child animation to run, the parent animation must query each of the elements containing child animations and then let the animations run using the animateChild() function.


1 Answers

Haven't done any animations myself yet, but according to : https://www.yearofmoo.com/2017/06/new-wave-of-animation-features.html#space-things-out-with-stagger

Your code should look like this instead:

animations: [
trigger('listAnimation', [
   transition('* => *', [
   // remember that :enter is a special
   // selector that will return each
   // newly inserted node in the ngFor list
   query(':enter', [
        style({
            transform: 'translate3d(0,-10px,0)',
            opacity: 0
        }),
        animate('0.1s', style({
            transform: 'translate3d(0,0,0)',
            opacity: 1
        }))
    ])
])  
]

That is adding a query level to what you already got

like image 159
Bulan Avatar answered Oct 11 '22 15:10

Bulan