gpt4 book ai didi

angular - 如何在 mat-tab-group 中为 Angular 更改过渡效果?

转载 作者:行者123 更新时间:2023-12-03 22:55:17 25 4
gpt4 key购买 nike

Angular mat-tab-group每个都有mat-tab已经包含动画效果。给定的动画效果很烦人,因此我想使用不同的动画效果。我已经有一个 fadeinfadeout来自某人 else .

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 的建议更新了示例。

最佳答案

我也不喜欢向左/向右滑动动画。你可以做这个我放在一起的变通方法淡入淡出动画。

您可以禁用 Angular Mat Tab 动画,然后在 中添加一些 css 关键帧动画。 mat-tab-body-active 类(class)。

要禁用动画,您可以在 mat-tab 中添加它。

<mat-tab-group [@.disabled]="true">

或者您可以在全局范围内禁用它 here

禁用动画后,将其添加到 style.css 文件中
.mat-tab-body.mat-tab-body-active {
animation: fade 0.5s;
}


@keyframes fade {
0% {
opacity: 0;
}

100% {
opacity: 1;
}
}

检查我的例子 here

关于angular - 如何在 mat-tab-group 中为 Angular 更改过渡效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56899503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com