此款進度條實現的功能:
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 = 0
21 $("#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>

