В проекте представлены два варианта анимации.
Вариант анимации 1, триггер ('animationOption1')
Работает без нареканий.
АнимацияВариант 2, триггер ('animationOption2')
Переход не работает здесь.
Онлайн проверить этот проект в StackBlitz.com
app.component.html
<h1>Animation Option 1</h1>
<div (click)="changeDivState()"
[@animationOption1]="clickedDivState"
>Click Me
</div>
<h1>Animation Option 2</h1>
<button (click)="toggleMenu()">Click Me</button>
<ul *ngIf="isMenuOpen"
[@animationOption2]="isMenuOpen ? 'open': 'close'"
>
<li>Menu Item 1</li>
<li>Menu Item 2</li>
<li>Menu Item 3</li>
</ul>
app.component.ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
animations: [
trigger('animationOption1', [
state('start', style({
backgroundColor: 'yellow',
width: '150px',
height: '150px'
})),
state('end', style({
backgroundColor: 'green',
width: '300px',
height: '300px'
})),
transition('start => end', animate(1500)),
transition('end => start', animate('800ms 0.5s ease-out'))
]),
trigger('animationOption2', [
state('close', style({
opacity: 0,
backgroundColor: 'yellow'
})),
state('open', style({
opacity: 1,
backgroundColor: 'green'
})),
transition('close <=> open', animate(3000)),
])
]
})
export class AppComponent {
isMenuOpen = false;
clickedDivState = 'start';
changeDivState() {
this.clickedDivState = 'end';
setTimeout(() => {
this.clickedDivState = 'start';
}, 3000);
}
toggleMenu(): void {
this.isMenuOpen = !this.isMenuOpen;
}
}
Поиск в Google не привел к решению.