typescript Angular 4基本动画#angular #js
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript Angular 4基本动画#angular #js相关的知识,希望对你有一定的参考价值。
import { HeroService } from './../../services/hero.service';
import { Hero } from './../../hero';
import {
Component,
Input
} from '@angular/core';
import {
trigger,
state,
style,
animate,
transition
} from '@angular/animations';
@Component({
selector: 'app-hero-list-basic',
styleUrls: ['./hero-list-basic.css'],
template: `
<ul style="width:250px;list-style:none;">
<li *ngFor="let hero of heroes"
[@heroState]="hero.state"
(@heroState.done)="animationDone($event)"
(click)="toggleState(hero)" class="module hero">
{{hero.name}}
</li>
</ul>
`,
animations: [
trigger('heroState', [
state('inactive', style({
transform: 'scale(1)'
})),
state('active', style({
transform: 'scale(0.5)'
})),
transition('inactive => active', animate('100ms ease-in')),
transition('active => inactive', animate('100ms ease-out'))
])
]
})
export class HeroListBasicComponent {
@Input() heroes: Hero[];
constructor(private heroService: HeroService) { }
ngOnInit(): void {
this.heroService.getHeroes()
.then(heroes => this.heroes = heroes.slice(1, 5));
}
toggleState(hero: Hero) {
hero.state = (hero.state === 'active' ? 'inactive' : 'active');
}
animationDone($event: Event) {
console.log('animation is over');
console.log($event);
}
}
以上是关于typescript Angular 4基本动画#angular #js的主要内容,如果未能解决你的问题,请参考以下文章
具有计算时间的 Angular 2 动画
如何在 Angular 2 中执行无限动画?
TypeScript 基本类型
带有 TypeScript 的 Angular 4:通过引用传递参数
typescript 4#todoapp-angular-ngrx
typescript 4#todoapp-angular-ngrx