Nav*_*med 20 typescript angular2-template angular2-services angular
我有一个组件从服务器获取项目列表,然后使用模板中的*ngFor显示该列表.
我希望列表显示一些动画,但一个接一个.我的意思是每个列表项应该在其他之后动画.
我正在尝试这样的事情:
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;
}
Run Code Online (Sandbox Code Playgroud)
在我的列表组件模板中我使用它像:
<ul>
<li *ngFor="let item of list;">
<list-item [item]="item"></list-item>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
它的作用是立即显示整个列表.我希望项目一个接一个地输入一些动画.
Ank*_*ngh 14
我在文档中找不到stagger支持ngFor,但现在animation.done events可以用来制作staggering ngFor
@Component({
selector: 'my-app',
template: `
<ul>
<li *ngFor="let hero of staggeringHeroes; let i = index"
(@flyInOut.done)="doNext()"
[@flyInOut]="'in'" (click)="removeMe(i)">
{{hero}}
</li>
</ul>
`,
animations: [
trigger('flyInOut', [
state('in', style({transform: 'translateX(0)'})),
transition('void => *', [
animate(300, keyframes([
style({opacity: 0, transform: 'translateX(-100%)', offset: 0}),
style({opacity: 1, transform: 'translateX(15px)', offset: 0.3}),
style({opacity: 1, transform: 'translateX(0)', offset: 1.0})
]))
]),
transition('* => void', [
animate(300, keyframes([
style({opacity: 1, transform: 'translateX(0)', offset: 0}),
style({opacity: 1, transform: 'translateX(-15px)', offset: 0.7}),
style({opacity: 0, transform: 'translateX(100%)', offset: 1.0})
]))
])
])
]
})
export class App {
heroes: any[] = ['Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot', 'Golf', 'Hotel', 'India'];
next: number = 0;
staggeringHeroes: any[] = [];
constructor(){
this.doNext();
}
doNext() {
if(this.next < this.heroes.length) {
this.staggeringHeroes.push(this.heroes[this.next++]);
}
}
removeMe(i) {
this.staggeringHeroes.splice(i, 1);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11739 次 |
| 最近记录: |