欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript實(shí)現(xiàn)網(wǎng)頁頭部進(jìn)度條刷新

 更新時間:2017年04月16日 08:57:55   投稿:mrr  
這篇文章主要介紹了JavaScript實(shí)現(xiàn)網(wǎng)頁頭部進(jìn)度條刷新實(shí)例代碼,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

本文刷新會頭部會出現(xiàn),因?yàn)椴]有真正的參與到瀏覽器加載是否完整這個渲染過程中來,所以只是一個表象,并不是說這個顯示完了就瀏覽器也加載完了所以資源。

效果圖:

先看下html:

就兩個標(biāo)簽

<div id="barbg">
   <div id="bar">
   </div>
  </div>

CSS:

布局也很簡單

 <style>
   *{margin:0;padding:0;}
   #barbg{height:5px; background:rgb(149,143,143)}
   #barbg div{width:0; height:5px; position:relative; background:rgb(230,10,10);}
  </style>

JS

然后原生JS的話就是這樣了

 <script>
   document.onreadystatechange = function(){
    var bar = document.getElementById('bar');
    var barbg = bar.parentNode;
    var wd = document.body.scrollWidth || document.documentElement.scrollWidth;
    var t = 10;
    var d = 0;
    var i = 0;
    var timer = setInterval(goto,10);
    function goto(){
     d = d + t ;
     bar.style.width = d + 'px';
     if(d >= wd){
      clearInterval(timer);
      bar.style.background = 'rgba(230,10,10,0)';
      none();
     }
    }
    function none(){
     var a = 10 - i;
     i++;
     if(a != 0 && a != 10){a = a * 0.1}
     if(a === 10){a = 1}
     if(a === 0){a = 0}
     barbg.style.background = 'rgba(230,10,10,' + a + ')';
     if(a === 0){barbg.style.display = 'none'}
     if(a != 0){setTimeout(none,50);}
    }
   }
  </script>

以上所述是小編給大家介紹的JavaScript實(shí)現(xiàn)網(wǎng)頁頭部進(jìn)度條刷新實(shí)例代碼,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的,在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論