I have a container that expands/shrinks. There is an element inside that container that should fade in when the container expands and fade out when the container shrinks.
My Problem
- When the container expands, the animation of both elements work.
- When the container shrinks, only the container animation works.
- If I remove the container expansion animation, then the fade in/out animations work as expected.
How do I make all animations execute in parallel under both expand/shrink conditions?
Note the use of ngIf. This is intentional as it destroys the element at the end of the animation sequence.
Here is a plunkr of my current state: https://embed.plnkr.co/TXYoGf9QpErWmlRvQF9Z/
The component class:
export class App {
expanded = true;
toggleExpandedState() {
this.expanded = !this.expanded;
}
constructor() {
}
}
The template:
<div class="container" [@expansionTrigger]="expanded">
<div class="constant-item"></div>
<div class="fade-item" [@stateAnimation] *ngIf="expanded"></div>
</div>
<button (click)="toggleExpandedState()">Toggle Fade</button>
and the component animation:
trigger('expansionTrigger', [
state('1', style({
width: '250px'
})),
state('0', style({
width: '160px'
})),
transition('0 => 1', animate('200ms ease-in')),
transition('1 => 0', animate('200ms ease-out'))
]),
trigger('stateAnimation', [
transition(':enter', [
style({
opacity: 0
}),
animate('200ms 350ms ease-in', style({
opacity: 1
}))
]),
transition(':leave', [
style({
opacity: 1
})
animate('1s', style({
opacity: 0
}))
])
])