Angular 5 Stagger Animation - How to do Reverse Order

♀尐吖头ヾ 提交于 2019-12-23 10:17:05

问题


While working with Angular CDK and developing a custom component, I am trying to implement stagger animation with ngIf and ngFor. The animation is a sequence of simple fade in.

The following simplified HTML:

<button (click)="visible = !visible">Toggle</button>
<div class="parent" @parentAnimation *ngIf="visible">
  <p class="child">Child 1</p>
  <p class="child">Child 2</p>
  <p class="child">Child 3</p>
</div>

And Component:

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ],
  animations: [
        trigger('parentAnimation', [
            transition('void => *', [
                query('.child', style({opacity: 0})),
                query('.child', stagger('500ms', [
                    animate('100ms .1s ease-out', style({opacity: 1}))
                ]))
            ]),
            transition('* => void', [
                query('.child', style({opacity: 1})),
                query('.child', stagger('500ms', [
                    animate('100ms .1s ease-out', style({opacity: 0}))
                ]))
            ])
        ])
    ]
})
export class AppComponent  {
   visible = false;
}

StackBlitz - https://stackblitz.com/edit/angular-5dj532

As can be seen in the link above, the issue is when hiding the elements, the order needs to be reversed (LIFO).

Looking at the stagger and query documentation, I could not find a built-in way to reverse the order.

Is there any proper way to implement this using angular animations?


回答1:


Use negative timing on the second stagger:

....
query('.child', stagger('-500ms', [....
...

Demo



来源:https://stackoverflow.com/questions/48334639/angular-5-stagger-animation-how-to-do-reverse-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!