Vue怎么防止白屏添加首屏动画

这篇“Vue怎么防止白屏添加首屏动画”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Vue怎么防止白屏添加首屏动画”文章吧。

单页应用有个无法避免的问题就是首屏加载慢,虽然可以通过gzip、路由懒加载、CDN、提高服务器带宽等手段,首屏加载速度仍然比传统多页应用慢一些。

为了提高用户体验,首屏添加loading动画很有必要,并且实现特别简单。

vue-cli3生成的项目中,打开index.html会发现如下代码

<body>
 <noscript>
  <strong>We're sorry but doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
 </noscript>
 <div id="app"></div>
 <!-- built files will be auto injected -->

我们只需要在这个div中插入loading代码即可,vue初始化完成后会自动替换

<div id="app">此处插入loading代码</div>

以下是我实现的一种动画效果,可自行替换

Vue怎么防止白屏添加首屏动画  vue 第1张

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
 <meta http-equiv="X-UA-Compatible" content="chrome=1"/>
 <link rel="icon" href="<%= BASE_URL %>favicon.ico" rel="external nofollow" >
 <link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_1112431_q8oa3yvrwbh.css" rel="external nofollow" >
 <title>demo</title>
 <style>
  .spinner {
   margin: 100px auto;
   width: 50px;
   height: 60px;
   text-align: center;
   font-size: 10px;
  }

  .spinner > div {
   background-color: #FE3C71;
   height: 100%;
   width: 6px;
   display: inline-block;
   -webkit-animation: stretchDelay 1.2s infinite ease-in-out;
   animation: stretchDelay 1.2s infinite ease-in-out;
  }

  .spinner .rect2 {
   -webkit-animation-delay: -1.1s;
   animation-delay: -1.1s;
  }

  .spinner .rect3 {
   -webkit-animation-delay: -1.0s;
   animation-delay: -1.0s;
  }

  .spinner .rect4 {
   -webkit-animation-delay: -0.9s;
   animation-delay: -0.9s;
  }

  .spinner .rect5 {
   -webkit-animation-delay: -0.8s;
   animation-delay: -0.8s;
  }

  @-webkit-keyframes stretchDelay {
   0%, 40%, 100% {
    -webkit-transform: scaleY(0.4)
   }
   20% {
    -webkit-transform: scaleY(1.0)
   }
  }

  @keyframes stretchDelay {
   0%, 40%, 100% {
    transform: scaleY(0.4);
    -webkit-transform: scaleY(0.4);
   }
   20% {
    transform: scaleY(1.0);
    -webkit-transform: scaleY(1.0);
   }
  }
 </style>
</head>
<body>
<noscript>
 <strong>We're sorry but demo doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app">
 <div class="spinner">
  <div class="rect1"></div>
  <div class="rect2"></div>
  <div class="rect3"></div>
  <div class="rect4"></div>
  <div class="rect5"></div>
 </div>
</div>
<!-- built files will be auto injected -->
</body>
</html>

以上就是关于“Vue怎么防止白屏添加首屏动画”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注蜗牛博客行业资讯频道。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:niceseo99@gmail.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

评论

有免费节点资源,我们会通知你!加入纸飞机订阅群

×
天气预报查看日历分享网页手机扫码留言评论电报频道链接