0
我正在嘗試添加動畫到我的角2應用程序,但它不工作,我試着用我從互聯網上得到的例子,我研究了一下,但我沒有找到任何事情,請任何人幫助我。角2.1.0過渡()不工作
import {Component, trigger, state, animate, transition, style} from '@angular/core';
@Component({
selector: 'app-root',
styles: [`
.container {
background-color: white;
border: 10px solid black;
width: 200px;
text-align: center;
font-size: 50px;
box-sizing: border-box;
overflow: hidden;
}
`],
animations: [
trigger('openClose', [
state('collapsed', style({ height: '0px', color: 'red' })),
state('expanded', style({ height: '100px', color: 'lightgreen' })),
transition('expanded <=> collapsed', animate(500))
])
],
template: `
<button (click)="expand()">Expand</button>
<button (click)="collapse()">Collapse</button>
<hr />
<div class="container" [@openClose]="animationState">
Look at this box
</div>
`
})
export class AppComponent {
animationState: string;
constructor() {
this.collapse();
}
expand() {
this.animationState = 'expanded';
}
collapse() {
this.animationState = 'collapsed';
}
}