1.在vue项目的public/index.html文件中添加以下代码,项目启动时进行加载loading动画
<head> <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> <div id="preloader"> <div id="preloader-inner"></div> </div> <div id="app"></div> </body>
2.在app.vue中进行删除动画
created() { let loading = document.getElementById('preloader'); if (loading !== null) { document.body.removeChild(loading); } }
本文为Jsky原创文章,转载无需和我联系,但请注明来自Jsky博客 www.tjin.link