Vue防止白屏添加首屏動畫的實例
單頁應(yīng)用有個無法避免的問題就是首屏加載慢,雖然可以通過gzip、路由懶加載、CDN、提高服務(wù)器帶寬等手段,首屏加載速度仍然比傳統(tǒng)多頁應(yīng)用慢一些。
為了提高用戶體驗,首屏添加loading動畫很有必要,并且實現(xiàn)特別簡單。
vue-cli3生成的項目中,打開index.html會發(fā)現(xiàn)如下代碼
<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>
以下是我實現(xiàn)的一種動畫效果,可自行替換
<!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" 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防止白屏添加首屏動畫的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用vue的v-for生成table并給table加上序號的實例代碼
這篇文章主要介紹了使用vue的v-for生成table并給table加上序號的相關(guān)資料,需要的朋友可以參考下2017-10-10vue導(dǎo)入excel文件,vue導(dǎo)入多個sheets的方式
這篇文章主要介紹了vue導(dǎo)入excel文件,vue導(dǎo)入多個sheets的方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08vue前端優(yōu)雅展示后端十萬條數(shù)據(jù)面試點剖析
這篇文章主要為大家介紹了vue前端優(yōu)雅展示后端十萬條數(shù)據(jù)的考點剖析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07Vue在echarts?tooltip中添加點擊事件案例詳解
本文主要介紹了Vue項目中在echarts?tooltip添加點擊事件的案例詳解,代碼具有一定的價值,感興趣的小伙伴可以來學(xué)習(xí)一下2021-11-11Vue.js實現(xiàn)在下拉列表區(qū)域外點擊即可關(guān)閉下拉列表的功能(自定義下拉列表)
這篇文章主要介紹了Vue.js實現(xiàn)在下拉列表區(qū)域外點擊即可關(guān)閉下拉列表的功能(自定義下拉列表) ,需要的朋友可以參考下2017-05-05