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

相关内容

热门资讯

脚本推荐!hhpoker有没有... 脚本推荐!hhpoker有没有作必弊辅助,hhpoker脚本下载(透视)好像真的有插件(哔哩哔哩)1...
透视关于!aa poker辅助... 透视关于!aa poker辅助,aapoker怎么设置抽水(透视)都是存在有脚本(哔哩哔哩)一、aa...
脚本教你!wpk辅助器是真的吗... 脚本教你!wpk辅助器是真的吗,wpk俱乐部有没有辅助(透视)本来是有方法(哔哩哔哩)1、实时透视辅...
脚本详情!德普之星app安卓版... 脚本详情!德普之星app安卓版破解版,德普之星透视辅助软件下载(透视)竟然有插件(哔哩哔哩)1、起透...
透视了解!德普之星私人局辅助器... 透视了解!德普之星私人局辅助器,德普之星辅助器app(透视)好像真的是有app(哔哩哔哩)1、下载好...
透视推荐!aapoker破解侠... 透视推荐!aapoker破解侠是真的吗,aapoker怎么提高中牌率(透视)确实真的有工具(哔哩哔哩...
脚本关于!aapoker脚本怎... 脚本关于!aapoker脚本怎么用,aapoker透视脚本(透视)本来是有技巧(哔哩哔哩)1、玩家可...
脚本了解!wpk可以作必弊吗,... 脚本了解!wpk可以作必弊吗,如何判断wpk辅助软件的真假(透视)总是是有神器(哔哩哔哩)1)辅助插...
脚本解谜!hhpoker德州有... 脚本解谜!hhpoker德州有挂吗,hhpoker透视工具(透视)切实真的有教程(哔哩哔哩)1、每一...
透视详细!wejoker辅助软... 透视详细!wejoker辅助软件视频,htx矩阵wepoker辅助(透视)本来真的是有神器(哔哩哔哩...