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

相关内容

热门资讯

透视代打"wepok... 透视代打"wepoker透视方法"详细辅助介绍教程(有挂软件);大神普及一款德州ai内幕,确定了we...
透视脚本"德州局hh... 透视脚本"德州局hhpoker"详细辅助力荐教程(私人局可以玩教程)准备好在德州局hhpoker i...
透视黑科技"wepo... 《透视黑科技"wepoker开脚本视频"详细辅助透明教程(私局代打技巧)》 wepoker开脚本视频...
透视美元局"hhpo... 透视美元局"hhpoker到底可以作弊码"详细辅助大神讲解(黑侠破解辅助);建议优先通过hhpoke...
透视总结"wepok... 透视总结"wepoker怎么设置房间"详细辅助玩家教你(万能挂透视);1.wepoker怎么设置房间...
透视苹果版"poke... 透视苹果版"pokemmo辅助官网"详细辅助德州论坛(内置辅助透视)1、不需要AI权限,帮助你快速的...
透视透视"wepok... 1、透视透视"wepoker有没有挂"详细辅助微扑克教程(插件下载透视);详细教程。2、wepoke...
透视工具"wepok... 1、透视工具"wepoker养号规律"详细辅助解密教程(购买模拟器攻略)(UU poker、wepo...
透视新版"菠萝辅助器... 透视新版"菠萝辅助器免费版的功能介绍"详细辅助玩家教你(是有挂软件教程);科技安装教程;136704...
辅助透视"wejok... 辅助透视"wejoker辅助软件视频"详细辅助2025教程(辅助脚本教程)是由北京得wejoker辅...