简体   繁体   English

如何在加载 Angular 应用程序之前显示动画?

[英]How to show an animation before loading Angular app?

I want to add a 2 second animation(SVG animation) screen, before my angular app shows up.我想在我的 angular 应用程序出现之前添加一个 2 秒动画(SVG 动画)屏幕。 So, each time someone goes to the url, the first 2 seconds will be of the animation, and then the Angular app will show up.因此,每次有人访问该 url 时,前 2 秒将是动画,然后 Angular 应用程序将出现。 Is this possible?这可能吗? I'd really appreciate any help in this, thanks and have a great day!我真的很感激这方面的任何帮助,谢谢,祝你有美好的一天!

Here's the code for the animation :这是动画的代码:

The svg code in html: html 中的 svg 代码:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="isolation:isolate" viewBox="0 0 700 680" width="700" height="680"><defs><clipPath id="_clipPath_wuO8YUgcuSMrLnSCtxnoIiXwy9UN2HRc"><rect width="700" height="680"/></clipPath></defs><g clip-path="url(#_clipPath_wuO8YUgcuSMrLnSCtxnoIiXwy9UN2HRc)"><g opacity="0.4"><path class="path1" d=" M 0 71.043 L 257.59 659.127 L 466.578 153.666 L 245.439 153.666" fill="none" vector-effect="non-scaling-stroke" stroke-width="8" stroke="#c6c6c6" stroke-linejoin="miter" stroke-linecap="butt" stroke-miterlimit="10"/></g></g></svg>

And the css:和CSS:

.path1{
    stroke-width:6;
    stroke-dasharray : 500;
    stroke-dashoffset : 1410.1248779296875;
    animation:test 6s linear alternate infinite;
}

@keyframes test{
    from{
        stroke-dashoffset:2351.569580078125; 
    }

    to{
        stroke-dashoffset:0;
    }
}

A simply solution would be to wait for 2 seconds in app component before proceeding一个简单的解决方案是在继续之前在应用程序组件中等待 2 秒

app.component.html应用程序组件.html

<ng-container *ngIf="animated">
  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="isolation:isolate" viewBox="0 0 700 680" width="700" height="680"><defs><clipPath id="_clipPath_wuO8YUgcuSMrLnSCtxnoIiXwy9UN2HRc"><rect width="700" height="680"/></clipPath></defs><g clip-path="url(#_clipPath_wuO8YUgcuSMrLnSCtxnoIiXwy9UN2HRc)"><g opacity="0.4"><path class="path1" d=" M 0 71.043 L 257.59 659.127 L 466.578 153.666 L 245.439 153.666" fill="none" vector-effect="non-scaling-stroke" stroke-width="8" stroke="#c6c6c6" stroke-linejoin="miter" stroke-linecap="butt" stroke-miterlimit="10"/></g></g></svg>
</ng-container>

<ng-container *ngIf="!animated">
<router-outlet></router-outlet>
</ng-container>

app.component.ts app.component.ts

export class AppComponent {

 animated = true;

  constructor() {
    setTimeout(() => {    // <<<---    using ()=> syntax
      this.animated = false;
      });
     }, 2000);
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM