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

相关内容

热门资讯

透视演示!we-poker软件... 透视演示!we-poker软件(德普之星私人局)一直真的有辅助脚本(哔哩哔哩)1、完成we-poke...
透视策略!聚星ai辅助工具激活... 您好,聚星ai辅助工具激活码这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】...
透视技法!wepoker破解工... 透视技法!wepoker破解工具(WePoKer透视脚本)原来存在有辅助攻略(哔哩哔哩)1、全新机制...
透视窍门!sohoo开挂辅助(... 透视窍门!sohoo开挂辅助(透视)werplan外卦神器(辅助)原来真的有神器(哔哩哔哩)1、we...
透视秘籍!德州局透视脚本免费版... 透视秘籍!德州局透视脚本免费版下载手机版(德普之星辅助软件)总是有辅助技巧(哔哩哔哩)1、上手简单,...
透视绝活!福建大菠萝万能辅助器... 透视绝活!福建大菠萝万能辅助器(透视)菠萝德普辅助器免费版在哪里(辅助)一贯真的有软件(哔哩哔哩)1...
透视手筋!wepoker透视底... 透视手筋!wepoker透视底牌(WePoKer系统)原来是真的有辅助脚本(哔哩哔哩)1、操作简单,...
透视举措!epoker免费透视... 透视举措!epoker免费透视脚本(透视)哈糖大菠萝万能挂(辅助)真是是有神器(哔哩哔哩)1、不需要...
透视手筋!德州局透视脚本免费版... 透视手筋!德州局透视脚本免费版下载手机版(透视)约局吧德州真的有透视挂吗(辅助)一直真的有脚本(哔哩...
透视课程!wepoker私人局... 透视课程!wepoker私人局可以透视(WPK控制牌)切实是真的有辅助教程(哔哩哔哩)1、任何wep...