Angular动画样式在动画结束后丢失
创始人
2024-10-24 13:31:50
0

这可能是由于Angular在动画结束后自动删除过渡样式引起的。要解决这个问题,我们可以使用以下方法:

1.在动画完成后,使用ngClass指定类名来应用动画样式:

@Component({ selector: 'app-example', animations: [ trigger('fadeInOut', [ state('void', style({ opacity: 0 })), transition('void <=> *', animate(1000)) ]) ] }) export class ExampleComponent { public show: boolean = false; public toggle(): void { this.show = !this.show; }

public onAnimationDone(event: AnimationEvent): void { if (event.toState !== 'void') { this.show ? this.element.classList.add('animation-in') : this.element.classList.add('animation-out'); } }

constructor(private readonly element: ElementRef) {} }

2.在动画完成后,使用setTimeOut()来延迟清除动画样式:

@Component({ selector: 'app-example', animations: [ trigger('fadeInOut', [ state('void', style({ opacity: 0 })), transition('void <=> *', animate(1000)) ]) ] }) export class ExampleComponent { public show: boolean = false; public toggle(): void { this.show = !this.show; }

public onAnimationDone(): void { setTimeout(() => { this.element.nativeElement.classList.remove('animation-in'); this.element.nativeElement.classList.remove('animation-out'); }); }

constructor(private readonly element: ElementRef) {} }

相关内容

热门资讯

技术分享!wepoker怎么设... 技术分享!wepoker怎么设置盖牌,wejoker手机版透视脚本,竟然是有挂(有挂教程)1、任何透...
总算了解!约局吧是否有挂,德州... 总算了解!约局吧是否有挂,德州私人局怎么透视,竟然是真的有挂(有挂总结)运辅助工具,进入游戏界面。进...
详细说明!wepoker安装教... 详细说明!wepoker安装教程,拱趴大菠萝万能挂,一直是真的有挂(今日头条)进入游戏-大厅左侧-新...
一分钟揭秘!哈糖大菠萝万能挂,... 一分钟揭秘!哈糖大菠萝万能挂,hhpoker怎么开透视,竟然有挂(有挂教程)一、可以开透视的定义与意...
必看攻略!德州辅助工具到底怎么... 必看攻略!德州辅助工具到底怎么样,wepoker辅助工具,真是真的是有挂(竟然有挂)1、打开软件启动...
查到实测辅助!wepoker俱... 查到实测辅助!wepoker俱乐部辅助器,wepoker辅助器是真的吗,真是有挂(有挂技巧)1、这是...
避坑细节!WePOker有没有... 避坑细节!WePOker有没有透视方法,wepoker软件辅助程序,果然有挂(有挂教学)1、用户打开...
玩家必知教程!wepoker破... 玩家必知教程!wepoker破解游戏盒子,佛手大菠萝13道挂哪里,果然是真的有挂(有挂分析)该软件可...
分享个大家!wepoker透视... 分享个大家!wepoker透视脚本免费,hhpoker德州真的假的,总是真的有挂(有挂教学)1、这是...
程序员教你!wpk透视是真的吗... 程序员教你!wpk透视是真的吗,wpk辅助插件,都是是有挂(有挂技巧)1、很好的工具软件,可以解锁游...