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

相关内容

热门资讯

反观!大菠萝免费辅助,微乐小程... 反观!大菠萝免费辅助,微乐小程序自建房辅助下载,专业透视(有挂细节)-哔哩哔哩1、不需要AI权限,帮...
透视普及!德普之星私人局透视,... 透视普及!德普之星私人局透视,德扑圈有透视吗(透视)确实有app(哔哩哔哩)一、游戏安装教程牌型概率...
昨日!哈糖大菠萝挂,微信小程序... 昨日!哈糖大菠萝挂,微信小程序微乐辅助器免费下载,透视脚本(有挂技巧)-哔哩哔哩在进入哈糖大菠萝挂软...
脚本分享!德扑HHpoker有... 脚本分享!德扑HHpoker有挂吗,德州局怎么透视(透视)本来真的是有器(哔哩哔哩)1、每一步都需要...
透视脚本!hardrock透视... 透视脚本!hardrock透视工具,微信微乐辅助ios,专业脚本(有挂秘诀)-哔哩哔哩;1、玩家可以...
脚本普及!德普软件,德普之星辅... 脚本普及!德普软件,德普之星辅助工具如何设置(透视)果然是真的挂(哔哩哔哩)亲,关键说明,透视脚本安...
透视好牌!wepoker作必弊... 透视好牌!wepoker作必弊视频,微信微乐游戏苹果辅助器,教你脚本(证实有挂)-哔哩哔哩1、点击下...
透视解谜!德普之星辅助工具如何... 透视解谜!德普之星辅助工具如何设置,德普之星透视(透视)其实真的有插件(哔哩哔哩)该软件可以轻松地帮...
今年以来!来玩德州破解器,微乐... 今年以来!来玩德州破解器,微乐自建房辅助工具下载入口在哪,关于脚本(讲解有挂)-哔哩哔哩1、全新机制...
透视神器!pokemmo手机版... 透视神器!pokemmo手机版修改器,淘宝的微乐辅助是真的吗,解密脚本(有挂猫腻)-哔哩哔哩在进入p...