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

相关内容

热门资讯

科普分享!wepoker买钻石... 科普分享!wepoker买钻石有用吗(辅助挂)其实真的有挂(有挂技巧辅助脚本)1、不需要AI权限,帮...
揭秘!hhpoker有没有作弊... 揭秘!hhpoker有没有作弊辅助(辅助挂)一贯真的是有挂(有挂讲解辅助插件)1、点击下载安装,脚本...
传递经验!pokemmo内置修... 传递经验!pokemmo内置修改器(辅助挂)总是存在有挂(有挂透明挂辅助app);透视方法中分为三种...
每日必看!wepoker买钻石... 每日必看!wepoker买钻石有用吗(辅助挂)原来真的是有挂(有挂辅助辅助脚本)1、该软件可以轻松地...
揭秘几款!德普之星透视辅助插件... 揭秘几款!德普之星透视辅助插件(辅助挂)好像是有挂(有挂技巧辅助app)1、许多玩家不知道辅助怎么退...
每日必备!wepoker怎么破... 每日必备!wepoker怎么破解游戏(辅助挂)确实存在有挂(有人有挂辅助攻略)1、免费脚本咨询教程、...
实操分享!hardrock透视... 实操分享!hardrock透视工具(辅助挂)都是是真的有挂(的确有挂辅助攻略)1、透视辅助软件激活码...
揭秘几款!wepoker免费脚... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
分享开挂内幕!哈糖大菠萝有挂吗... 分享开挂内幕!哈糖大菠萝有挂吗5个常用方法(辅助挂)本来是真的有挂(有挂分享辅助技巧)1、实时透视辅...
2分钟细说!wepokerpl... 2分钟细说!wepokerplus透视脚本免费(辅助挂)真是真的有挂(有挂总结辅助软件)1、实时透视...