Angular 2
Animacja
Szukaj…
Przejście między stanami zerowymi
@Component({
...
animations: [
trigger('appear', [
transition(':enter', [
style({
//style applied at the start of animation
}),
animate('300ms ease-in', style({
//style applied at the end of animation
}))
])
])
]
})
class AnimComponent {
}
]
Animacja między wieloma stanami
<div> w ten szablon rośnie do 50px , a następnie 100px a następnie kurczy się z powrotem do 20px po kliknięciu przycisku.
Każdy state ma powiązany styl opisany w metadanych @Component .
Logiką dla dowolnego state jest zarządzana w logice komponentu. W tym przypadku size zmiennej składowej zawiera wartość łańcucha „mały”, „średni” lub „duży”.
Element <div> odpowiada na tę wartość za pomocą trigger określonego w metadanych @Component : [@size]="size" .
@Component({
template: '<div [@size]="size">Some Text</div><button (click)="toggleSize()">TOGGLE</button>',
animations: [
trigger('size', [
state('small', style({
height: '20px'
})),
state('medium', style({
height: '50px'
})),
state('large', style({
height: '100px'
})),
transition('small => medium', animate('100ms')),
transition('medium => large', animate('200ms')),
transition('large => small', animate('300ms'))
])
]
})
export class TestComponent {
size: string;
constructor(){
this.size = 'small';
}
toggleSize(){
switch(this.size) {
case 'small':
this.size = 'medium';
break;
case 'medium':
this.size = 'large';
break;
case 'large':
this.size = 'small';
}
}
}
Modified text is an extract of the original Stack Overflow Documentation
Licencjonowany na podstawie CC BY-SA 3.0
Nie związany z Stack Overflow