基於JQuery的進度條實現

來源:互聯網
上載者:User

標籤:padding   direct   填充   hit   即時   文本   dir   依賴   .com   

功能描述:顧名思義,既是形象地用柱狀條長短變化表示進度變化過程的工具。如:

實現

  • 組成:單看進度條的組成,外層是一個父標籤,有一定長度,有邊框,便於表現總的進度大小;裡層是一個子標籤,寬度為一定百分比的父標籤寬度,並且背景色填充,有常值內容,文本居右,有一定內邊距。
  • 動畫:為子標籤設定一個輪詢者,當寬度達到父標籤寬度100%時,關閉輪詢者,並做自訂動作

代碼:

  • HTML
 1 <!doctype html> 2 <html> 3     <head> 4         <meta charset="utf-8"> 5         <title>我的進度條</title> 6         <link rel="stylesheet" type="text/css" href="progress.css"> 7         <script type="text/javascript" src="jquery-1.11.3.min.js"></script> 8         <script type="text/javascript" src="progress.js"></script> 9     </head>10     <body>11         <div class="flex-center">12             <h3>系統載入中,請稍等...</h3>13             <span class="container">14                 <span id="progressBar" class="h-100P bar"></span>15             </span>16         </div>17     </body>18 </html>

引用自己寫的CSS樣式檔案,再引入Jquery的Js檔案,和自己寫的JS檔案。自己寫的JS檔案依賴於JQuery檔案。

  • CSS
 1 .flex-center{ 2     display: flex; 3     flex-direction: column; 4     align-items: center; 5 } 6 .container{ 7         display: inline-block; 8         width: 50%; 9         height: 20px;10         padding-right: 10px;11         border: 1px solid #999;12         border-radius: 5px; 13 }14 .h-100P{15         height: 100%;16 }17 .bar{18         display: inline-block;19         background: #90bf46;20         color: white;21         font-weight: bold;22         padding: 0 5px;23         text-align: right;24         border-radius: 5px;25         border-right: 1px solid #999;26 }

父標籤引用container樣式,子標籤引用bar樣式。

  • JS
 1 $(document).ready(function () { 2     var percentage = 0; 3     var interval = setInterval(function () { 4         if (percentage < 10000) { 5             percentage++; 6             var widthTemp = (percentage / 100).toFixed(1) + ‘%‘; 7             $(‘#progressBar‘).css(‘width‘, widthTemp); 8             $(‘#progressBar‘).text(widthTemp); 9         } else {10             clearInterval(interval);11             $(‘h3‘).text(‘載入完成!正在為您跳轉...‘);12             setTimeout(function () {13                 location = ‘helloWorld.html‘;14             }, 1500);15         }16     }, 10);17 });

$(document).ready()方法初始化JS檔案,JS代碼從這裡開始執行。當percentage初始化為0,每10毫秒自加一次,自加10000次,既100000毫秒(100秒)後結束迴圈,迴圈時,即時改變子標籤的寬度,並更改顯示的常值內容。

基於JQuery的進度條實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.