bootstrap與jQuery結合的動態進度條

來源:互聯網
上載者:User

標籤:incr   最新   script   技術   ret   初始化   ie瀏覽器   黃色   addclass   

此款進度條實現的功能:

1.利用了bootstrap的進度條組件。

  a.在最外層的<div>中加入class .progress,在裡層<div>加入class .progress-bar從而實現基本的進度條。

  b.在外層<div>中加入class .progress-striped實現條紋進度條。

  c.在內層<div>加入class .progress-bar-danger/warning/info/success 從而實現紅色、黃色、藍色、綠色

  d.在外層<div>中加入class .active 實現動畫效果

2.利用jQuery對進度條進度進行控制。

  0-30時顯示紅色,30-60顯示黃色,60-90顯示綠色,90-100顯示綠色

  實現進度條暫停、停止、重新開始、繼續功能

具體代碼如下:

 1 <!DOCTYPE html> 2 <html lang="zh-CN"> 3 <head> 4     <meta charset="UTF-8"> 5     <title>...</title> 6     <!--在IE瀏覽器中運行最新的渲染模式--> 7     <meta http-equiv="X-UA-Compatible" content="IE-Edge"> 8     <!--初始化行動瀏覽器顯示--> 9     <meta name="viewport" content="width-device-width,inital-scale=1">10     <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">11     <link rel="stylesheet" type="text/css" href="index.css">12     <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>13       <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>14       <script type="text/javascript">15           $(document).ready(function(){16               var value = 0;17               var time = 50;18               //進度條複位函數19               function reset( ) {20                 value = 021                   $("#prog").removeClass("progress-bar-success").css("width","0%").text("等待啟動");22                   //setTimeout(increment,5000);23               }24               //百分數增加,0-30時為紅色,30-60為黃色,60-90為藍色,>90為綠色25               function increment( ) {26                   value += 1;27                   $("#prog").css("width",value + "%").text(value + "%");28                   if (value>=0 && value<=30) {29                       $("#prog").addClass("progress-bar-danger");30                   }31                   else if (value>=30 && value <=60) {32                       $("#prog").removeClass("progress-bar-danger");33                       $("#prog").addClass("progress-bar-warning");34                   }35                   else if (value>=60 && value <=90) {36                       $("#prog").removeClass("progress-bar-warning");37                       $("#prog").addClass("progress-bar-info");38                   }39                   else if(value >= 90 && value<100) {40                       $("#prog").removeClass("progress-bar-info");41                       $("#prog").addClass("progress-bar-success");    42                   }43                   else{44                       setTimeout(reset,3000);45                       return;46 47                   }48 49                   st = setTimeout(increment,time);50               }51 52               increment();53               //進度條停止與重新開始54               $("#stop").click(function () {55                   if ("stop" == $("#stop").val()) {56                       //$("#prog").stop();57                       clearTimeout(st);58                       $("#prog").css("width","0%").text("等待啟動");59                       $("#stop").val("start").text("重新開始");60                   } else if ("start" == $("#stop").val()) {61                       increment();62                       $("#stop").val("stop").text("停止");                      63                   }64               });65               //進度條暫停與繼續66               $("#pause").click(function() {67                   if ("pause" == $("#pause").val()) {68                       //$("#prog").stop();69                       clearTimeout(st);70                       $("#pause").val("goon").text("繼續");71                   } else if ("goon" == $("#pause").val()) {72                       increment();73                       $("#pause").val("stop").text("暫停");74                   }75               });76           });77       </script>78 </head>79 <body>80     <div class="progress progress-striped active">81         <div id="prog" class="progress-bar" role="progressbar" aria-valuenow="" aria-valuemin="0" aria-valuemax="100" style="width:0%;">82             <span id="proglabel">正在啟動,請稍後......</span>83         </div>84     </div>    85     <div class="form-group">86         <div class="col-sm-offset-4 col-sm-6">87             <button id="pause" class="btn btn-primary" value="pause">暫停</button>88             <button id="stop" class="btn btn-primary" value="stop">停止</button>89             <!--<button id="goon" class="btn btn-primary">繼續<button>-->90         </div>91     </div>            92 </body>93 </html>

bootstrap與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.