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有辅助插件吗,微乐自建房辅助下载,讲义教程(有挂教程)-哔哩哔哩wepoke...
详细透视!wpk德州局透视,微... 详细透视!wpk德州局透视,微乐陕西小程序脚本,指南教程(果真有挂)-哔哩哔哩一、wpk德州局透视游...
辅助透视!hhpoker作弊码... 辅助透视!hhpoker作弊码怎么用,微乐小程序怎么挂脚本,技法教程(真的有挂)-哔哩哔哩hhpok...
了解透视!wepoker辅助器... 了解透视!wepoker辅助器如何使用,微信微乐小程序修改器,手册教程(有挂秘籍)-哔哩哔哩1、玩家...
了解透视!wepoker代打辅... 了解透视!wepoker代打辅助,微乐家乡脚本助手,经验教程(有挂秘笈)-哔哩哔哩在进入wepoke...
揭幕透视!wepoker透视功... 揭幕透视!wepoker透视功能下载,微信小程序微乐辅助器教程,手筋教程(真的有挂)-哔哩哔哩1、操...
教你透视!菠萝辅助器免费版的特... 教你透视!菠萝辅助器免费版的特点,微乐自建房辅助工具,总结教程(竟然有挂)-哔哩哔哩菠萝辅助器免费版...
辅助透视!wpk有那种辅助吗,... 辅助透视!wpk有那种辅助吗,微乐自建房辅助工具官网,攻略教程(有挂方法)-哔哩哔哩1、wpk有那种...
辅助透视!wepokerplu... 辅助透视!wepokerplus脚本,微信小程序微乐辅助器教程,课程教程(有挂总结)-哔哩哔哩1、下...
必备透视!pokemmo脚本,... 必备透视!pokemmo脚本,微信微乐自建房辅助工具,阶段教程(有挂存在)-哔哩哔哩1、进入游戏-大...