之前我用过Pace来显示WordPress页面的加载进度和加载动画,但觉得很鸡肋,所以就放弃了。最近我在知乎看到有人整理了几个漂亮的加载动画,就又想添加起来试试。(仍然很鸡肋)
原贴地址:https://zhuanlan.zhihu.com/p/24464355
我用的是里面的第一个:CSS loader
效果如下:
 
要添加的话其实也很简单。
1 添加或引入css
将下列代码添加到head.php,或者新建成css文件再引入到head。
- <style>    
 - body {    
 -   margin: 0;    
 - }    
 - .loader {    
 -   position: absolute;    
 -   top: 50%;    
 -   left: 40%;    
 -   margin-left: 10%;    
 -   transform: translate3d(-50%, -50%, 0);    
 - }    
 - .dot {    
 -   width: 24px;    
 -   height: 24px;    
 -   background: #3ac;    
 -   border-radius: 100%;    
 -   display: inline-block;    
 -   animation: slide 1s infinite;    
 - }    
 - .dot:nth-child(1) {    
 -   animation-delay: 0.1s;    
 -   background: #32aacc;    
 - }    
 - .dot:nth-child(2) {    
 -   animation-delay: 0.2s;    
 -   background: #64aacc;    
 - }    
 - .dot:nth-child(3) {    
 -   animation-delay: 0.3s;    
 -   background: #96aacc;    
 - }    
 - .dot:nth-child(4) {    
 -   animation-delay: 0.4s;    
 -   background: #c8aacc;    
 - }    
 - .dot:nth-child(5) {    
 -   animation-delay: 0.5s;    
 -   background: #faaacc;    
 - }    
 - @-moz-keyframes slide {    
 -   0% {    
 -     transform: scale(1);    
 -   }    
 -   50% {    
 -     opacity: 0.3;    
 -     transform: scale(2);    
 -   }    
 -   100% {    
 -     transform: scale(1);    
 -   }    
 - }    
 - @-webkit-keyframes slide {    
 -   0% {    
 -     transform: scale(1);    
 -   }    
 -   50% {    
 -     opacity: 0.3;    
 -     transform: scale(2);    
 -   }    
 -   100% {    
 -     transform: scale(1);    
 -   }    
 - }    
 - @-o-keyframes slide {    
 -   0% {    
 -     transform: scale(1);    
 -   }    
 -   50% {    
 -     opacity: 0.3;    
 -     transform: scale(2);    
 -   }    
 -   100% {    
 -     transform: scale(1);    
 -   }    
 - }    
 - @keyframes slide {    
 -   0% {    
 -     transform: scale(1);    
 -   }    
 -   50% {    
 -     opacity: 0.3;    
 -     transform: scale(2);    
 -   }    
 -   100% {    
 -     transform: scale(1);    
 -   }    
 - }    
 - </style>    
 
 
2 添加html标签
将下列代码添加到head.php
- <div id="pre-loader" class="loader">  
 -   <div class="dot"></div>  
 -   <div class="dot"></div>  
 -   <div class="dot"></div>  
 -   <div class="dot"></div>  
 -   <div class="dot"></div>  
 - </div>  
 
 
3 判断网页加载完成,移除动画
将下列代码添加到head.php
- <script type="text/javascript">           
 -         document.onreadystatechange = function () {  
 -             if(document.readyState=="complete") {  
 -                 $("#pre-loader").fadeOut("slow");  
 -                 document.getElementById("pre-loader").remove();  
 -             }  
 -         }  
 - </script>    
 
 
 
Comments | NOTHING