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) {} }

相关内容

热门资讯

透视神器!pokemmo辅助器... 透视神器!pokemmo辅助器手机版下载,wepoker辅助是真的假的(透视)揭幕教程(有挂方式)-...
据了解!拱趴大菠萝有什么挂,w... 据了解!拱趴大菠萝有什么挂,wepoker有人用过吗(透视)专业教程(证实有挂)-哔哩哔哩1、进入游...
透视辅助!wepoker辅助透... 透视辅助!wepoker辅助透视软件,hhpoker必备开挂(透视)详细教程(证实有挂)-哔哩哔哩1...
长期以来!we poker游戏... 长期以来!we poker游戏下,智星德州插件(透视)详细教程(有挂方式)-哔哩哔哩1)智星德州插件...
透视app!werplan脚本... 透视app!werplan脚本,aapoker透视插件(透视)总结教程(有挂规律)-哔哩哔哩1、全新...
现有关情况通报如下!hhpok... 现有关情况通报如下!hhpoker辅助挂是真的吗,wepoker免费透视脚本(透视)解谜教程(果真有...
长期以来!wepoker新号好... 长期以来!wepoker新号好一点吗,wepoker黑侠辅助器正版下载(透视)解谜教程(有挂秘籍)-...
透视肯定!wepoker辅助透... 透视肯定!wepoker辅助透视软件,德普之星辅助工具如何打开(透视)总结教程(有挂分享)-哔哩哔哩...
现场直击!aa poker辅助... 现场直击!aa poker辅助,wepoker怎么破解游戏(透视)专业教程(竟然有挂)-哔哩哔哩we...
透视了解!wpk德州局透视,w... 透视了解!wpk德州局透视,wepoker有什么规律(透视)详情教程(今日头条)-哔哩哔哩1、完成w...