頁面進度條事件

來源:互聯網
上載者:User

使用者體驗,這年頭提的特別多。其實,說白了就是細節方面的處理。今天,講一個進度條的體驗效果。

直接貼代碼,想嘗試看效果的,自己copy到編輯器裡到網頁view吧。

<!DOCTYPE><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>進度條事件</title><style type="text/css" media="screen">*{margin:0; padding: 0;}.f-wrap{margin:100px auto; width: 1000px;}p{ line-height: 24px; padding: 10px 0;}.s-gray{color:#999;}#progressBar{width:800px; height:25px; border:1px solid #ddd; background-color: #fff; position: relative; }#progressBar #bar,#progressBar #text{ position:absolute; top:0; left: 0; z-index: 1; width:100%; font-weight: bold; font-family:georgia; font-size: 16px; text-align: center; height:25px; line-height:25px;}#progressBar #bar{z-index:2; background-color:blue; color:#fff; clip:rect(0px,0,25px,0);}</style></head><body><div class="f-wrap"><div id="progressBar"><div id="bar">0%</div><div id="text">0%</div></div><div class="s-gray"><p>clip是css2中的一個樣式</p><ol><li>寫入程式碼:寫死</li><li>跟flash配合,as3</li><li>html5 : xhr2 :onprogress onload</li><li>跟背景配合,ajax即時返回(cent)</li></ol></div></div><script>     window.onload = function(){     var iProgress = 0;     var timer = null;     timer = setInterval(function(){            if(iProgress == 100){                 clearInterval(timer);            }else{            iProgress+=5;                progressFn(iProgress);            }     },100);                // 封裝成一個函數     function progressFn(cent){              var oDiv1 = document.getElementById('progressBar');              var oDiv2 = document.getElementById('bar');              var oDiv3 = document.getElementById('text');                            var objW = parseInt(getStyle(oDiv1,'width'));              oDiv2.innerHTML = cent + '%';              oDiv3.innerHTML = cent + '%';              oDiv2.style.clip = 'rect(0px, '+ cent/100 * objW +'px, 25px, 0)';              // 擷取樣式值              function getStyle(obj,attr){                if(obj.currentStyle){                  return obj.currentStyle[attr];                }else{                  return getComputedStyle(obj,false)[attr];                }              }     }     }</script></body></html>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.