Angular 动画:动画父元素和子元素
Angular Animations: Animate Parent and Child Elements
我创建了一个带有 Angular 动画的元素 (div.parent
),效果很好。当我向它添加一个子元素并尝试同时为该子元素设置动画时,其中一个动画不会结束 运行(它只是捕捉到新状态)。
堆栈闪电战:
https://stackblitz.com/edit/angular-2tbwu8
标记:
<div [@theParentAnimation]="state" class="parent">
<div [@theChildAnimation]="state" class="child">
</div>
</div>
动画:
trigger( 'theParentAnimation', [
state( 'down', style( {
transform: 'translateY( 100% ) translateZ( 0 )',
} ) ),
transition( '* <=> *', [
group( [
query( ':self', [
animate( '0.9s cubic-bezier(0.55, 0.31, 0.15, 0.93)' ),
] ),
query( '@theChildAnimation', animateChild() ),
] ),
] ),
] ),
trigger( 'theChildAnimation', [
state( 'down', style( {
transform: 'translateY( 100% ) translateZ( 0 )',
} ) ),
transition( '* <=> *', [
animate( '0.9s cubic-bezier(0.55, 0.31, 0.15, 0.93)' ),
] ),
] ),
看起来您不需要使用 query( ':self', ...
,因为您使用的是 group()
动画将 运行 并行。您可以更改父动画中的过渡:
transition('* <=> *', [
group([
query('@theChildAnimation', animateChild()),
animate('0.9s cubic-bezier(0.55, 0.31, 0.15, 0.93)'),
]),
]),
我创建了一个带有 Angular 动画的元素 (div.parent
),效果很好。当我向它添加一个子元素并尝试同时为该子元素设置动画时,其中一个动画不会结束 运行(它只是捕捉到新状态)。
堆栈闪电战: https://stackblitz.com/edit/angular-2tbwu8
标记:
<div [@theParentAnimation]="state" class="parent">
<div [@theChildAnimation]="state" class="child">
</div>
</div>
动画:
trigger( 'theParentAnimation', [
state( 'down', style( {
transform: 'translateY( 100% ) translateZ( 0 )',
} ) ),
transition( '* <=> *', [
group( [
query( ':self', [
animate( '0.9s cubic-bezier(0.55, 0.31, 0.15, 0.93)' ),
] ),
query( '@theChildAnimation', animateChild() ),
] ),
] ),
] ),
trigger( 'theChildAnimation', [
state( 'down', style( {
transform: 'translateY( 100% ) translateZ( 0 )',
} ) ),
transition( '* <=> *', [
animate( '0.9s cubic-bezier(0.55, 0.31, 0.15, 0.93)' ),
] ),
] ),
看起来您不需要使用 query( ':self', ...
,因为您使用的是 group()
动画将 运行 并行。您可以更改父动画中的过渡:
transition('* <=> *', [
group([
query('@theChildAnimation', animateChild()),
animate('0.9s cubic-bezier(0.55, 0.31, 0.15, 0.93)'),
]),
]),