Vue防止白屏添加首屏动画的实例

所属分类: 网络编程 / JavaScript 阅读数: 348
收藏 0 赞 0 分享

单页应用有个无法避免的问题就是首屏加载慢,虽然可以通过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>

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

<!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防止白屏添加首屏动画的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

jquery实现可拖拽弹出层特效

这篇文章主要介绍了jquery实现可拖拽弹出层特效,代码非常精简,效果非常棒,这里推荐给有需要的小伙伴
收藏 0 赞 0 分享

浅谈 javascript 事件处理

本文向大家简单介绍了javascript的事件处理机制,从事件源,事件操作到事件处理程序都做了简单介绍,并给出了部分示例,这里推荐给大家。
收藏 0 赞 0 分享

jQuery中:reset选择器用法实例

这篇文章主要介绍了jQuery中:reset选择器用法,实例分析了:reset选择器的功能、定义及匹配重置按钮的使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

原生javascript实现隔行换色

这篇文章主要介绍了原生javascript实现隔行换色,需要的朋友可以参考下
收藏 0 赞 0 分享

jQuery中:button选择器用法实例

这篇文章主要介绍了jQuery中:button选择器用法,实例分析了:button选择器的功能、定义及选取按钮的使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

jQuery中:file选择器用法实例

这篇文章主要介绍了jQuery中:file选择器用法,实例分析了:file选择器的功能、定义及选取类型为file的<input>元素的使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

jQuery中:enabled选择器用法实例

这篇文章主要介绍了jQuery中:enabled选择器用法,实例分析了:enabled选择器的功能、定义及选取所有可用元素的使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

AngularJS中取消对HTML片段转义的方法例子

这篇文章主要介绍了AngularJS中取消对HTML片段转义的方法例子,在一些需要显示HTML的地方,就要取消AngularJS的转义,本文就介绍了这种方法,需要的朋友可以参考下
收藏 0 赞 0 分享

jQuery中:disabled选择器用法实例

这篇文章主要介绍了jQuery中:disabled选择器用法,实例分析了:disabled选择器功能、定义及选取所有禁用的表单元素的技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

jQuery中:checked选择器用法实例

这篇文章主要介绍了jQuery中:checked选择器用法,实例分析了:checked选择器的功能、定义及选取选中的复选框或单选按钮时的使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多