【问题标题】:How to delay each ngFor items animation如何延迟每个 ngFor 项目动画
【发布时间】:2017-02-07 15:21:47
【问题描述】:

如何延迟 *ngFor 的每个项目以逐个设置动画?

我的意思是这样的:

<li *ngFor="let item of items"> //end result like below:
  <a [@flyIn]="'in'">first item</a> // delay 100ms and animate
  <a [@flyIn]="'in'">first item</a> // delay 200ms and animate
  <a [@flyIn]="'in'">first item</a> // delay 300ms and animate
  <a [@flyIn]="'in'">first item</a> // delay 400ms and animate
  <a [@flyIn]="'in'">first item</a> // delay 500ms and animate
</li>

我是否需要每隔一段时间将项目添加到项目数组中,或者是否有一些更简单的方法?

【问题讨论】:

标签: angular angular2-animation


【解决方案1】:

这现在应该可以在 Angular 4.2 中实现(虽然我自己还没有测试过)。下面的例子是从this blog post复制过来的:

模板代码:

<div [@races]="races?.length">
  <button class="btn btn-primary mb-2" (click)="toggle()">Toggle</button>
  <div *ngFor="let race of races | slice:0:4">
    <h2>{{race.name}}</h2>
    <p>{{race.startInstant}}</p>
  </div>
</div>

动画代码:

trigger('races', [
  transition('* => *', [
    query(':leave', [
      stagger(500, [
        animate(1000, style({ opacity: 0 }))
      ])
    ], { optional: true }),
    query(':enter', [
      style({ opacity: 0 }),
      animate(1000, style({ opacity: 1 }))
    ], { optional: true })
  ])
])

【讨论】:

    猜你喜欢
    • 2017-01-06
    • 1970-01-01
    • 2019-02-10
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 2012-06-25
    • 1970-01-01
    相关资源
    最近更新 更多