Angular的
尝试像这样应用:
mat-tab-group
已经包含了每个mat-tab
的动画效果。但是给定的动画效果相当烦人,因此我想使用不同的动画效果。我已经从别人那里获得了一个fadein
和fadeout
的动画效果。链接
export const fadeAnimation = trigger('fadeAnimation', [
// The '* => *' will trigger the animation to change between any two states
transition('* => *', [
// The query function has three params.
// First is the event, so this will apply on entering or when the element is added to the DOM.
// Second is a list of styles or animations to apply.
// Third we add a config object with optional set to true, this is to signal
// angular that the animation may not apply as it may or may not be in the DOM.
query(
':enter',
[style({ opacity: 0 })],
{ optional: true }
),
query(
':leave',
// here we apply a style and use the animate function to apply the style over 0.3 seconds
[style({ opacity: 1 }), animate('0.3s', style({ opacity: 0 }))],
{ optional: true }
),
query(
':enter',
[style({ opacity: 0 }), animate('0.3s', style({ opacity: 1 }))],
{ optional: true }
)
])
]);
尝试像这样应用:
<mat-tab-group animationDuration="0ms">
<mat-tab label="First">
<div [@fadeAnimation]="'enter'">
Content 1
</div>
</mat-tab>
<mat-tab label="Second"> Content 2 </mat-tab>
<mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>
执行失败。有没有提示如何正确应用它?
根据@ysf的建议更新了示例。
mat-tab-group
允许控制动画的持续时间,如此处所述,但这并不是你想要的。为了应用自定义动画,您需要在选项卡组上禁用Angular动画并实现自己的CSS动画。 - ysfanimationDuration
也不适用吗? - LeO