vue中使用 preloader进行首屏加载时间长添加加载动画

Jsky博客


在vue中的 index.html 加上这个div 就可以在首屏加载的时候 使用

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
    <title>小巧的jQuery页面预加载指示器插件</title>
    <style>
        #preloader {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 1000;
        }

        #preloader #preloader-inner {
            display: block;
            position: relative;
            left: 50%;
            top: 50%;
            width: 70px;
            height: 70px;
            margin: -35px 0 0 -35px;
            border-radius: 50%;
            border: 3px solid transparent;
            border-top-color: #3498db;
            animation: spin 2s linear infinite;
        }

        #preloader #preloader-inner:before {
            content: "";
            position: absolute;
            top: 5px;
            left: 5px;
            right: 5px;
            bottom: 5px;
            border-radius: 50%;
            border: 3px solid transparent;
            border-top-color: #e74c3c;
            animation: spin 3s linear infinite;
        }

        #preloader #preloader-inner:after {
            content: "";
            position: absolute;
            top: 15px;
            left: 15px;
            right: 15px;
            bottom: 15px;
            border-radius: 50%;
            border: 3px solid transparent;
            border-top-color: #f9c922;
            animation: spin 1.5s linear infinite;
        }

        @keyframes spin {
            0% {
                transform: rotate(0deg);
            }

            to {
                transform: rotate(1turn);
            }
        }
    </style>
</head>

<body>
  <!--Preloader element -->
  <div id="preloader">
    <div id="preloader-inner"></div>
</div>
  <div id="app"></div>
</body>

</html>


在vue中关闭这个加载动画 放在app.vue 文件中进行关闭

    created(){
      let loading = document.getElementById('preloader');
      if(loading !== null){
        document.body.removeChild(loading);
      }
    },


Jsky博客
请先登录后发表评论
  • 最新评论
  • 总共0条评论