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

相关内容

热门资讯

受玩家影响!德州局透视脚本,随... 受玩家影响!德州局透视脚本,随意玩5元流量包-真是真的有辅助下载(哔哩哔哩)1、下载好随意玩5元流量...
透视脚本!sohoo辅助,闲逸... 透视脚本!sohoo辅助,闲逸透视app下载安装-一直真的是有辅助插件(哔哩哔哩)1、用户打开应用后...
透视能赢!wejoker透视方... 透视能赢!wejoker透视方法,多乐破解游戏盒子破解版-一贯真的是有辅助插件(哔哩哔哩)小薇(辅助...
透视肯定!impoker辅助,... 透视肯定!impoker辅助,八大碗辅助器app辅助-确实真的有辅助软件(哔哩哔哩)1、用户打开应用...
目前来看!wepoker如何设... 目前来看!wepoker如何设置透视,微乐春天扑克开挂辅助插件-好像存在有辅助平台(哔哩哔哩)1、微...
透视app!wejoker私人... 透视app!wejoker私人辅助软件,兴动助手辅助器-一直是真的辅助修改器(哔哩哔哩)1、打开软件...
透视智能ai!德普之星透视辅助... 透视智能ai!德普之星透视辅助软件,悦悦娱乐辅助,有挂教程(竟然是有辅助修改器)-哔哩哔哩悦悦娱乐辅...
记者获悉!aapoker真的假... 记者获悉!aapoker真的假的(透视)闲聚app辅助软件(真是真的有辅助辅助器)-哔哩哔哩1、任何...
透视黑科技!竞技联盟透视插件(... 透视黑科技!竞技联盟透视插件(透视)微乐南昌辅助神器(好像是有辅助辅助器)-哔哩哔哩1、微乐南昌辅助...
无独有偶!aapoker真的假... 无独有偶!aapoker真的假的(透视)椰岛常胜游戏辅助工具免费版(本来真的有辅助app)-哔哩哔哩...