您好,登錄后才能下訂單哦!
本文實(shí)例講述了bootstrap+jQuery實(shí)現(xiàn)的動(dòng)態(tài)進(jìn)度條功能。分享給大家供大家參考,具體如下:
此款進(jìn)度條實(shí)現(xiàn)的功能:
1.利用了bootstrap的進(jìn)度條組件。
a.在最外層的<div>中加入class .progress,在里層<div>加入class .progress-bar從而實(shí)現(xiàn)基本的進(jìn)度條。
b.在外層<div>中加入class .progress-striped實(shí)現(xiàn)條紋進(jìn)度條。
c.在內(nèi)層<div>加入class .progress-bar-danger/warning/info/success 從而實(shí)現(xiàn)紅色、黃色、藍(lán)色、綠色
d.在外層<div>中加入class .active 實(shí)現(xiàn)動(dòng)畫效果
2.利用jQuery對(duì)進(jìn)度條進(jìn)度進(jìn)行控制。
0-30時(shí)顯示紅色,30-60顯示黃色,60-90顯示綠色,90-100顯示綠色
實(shí)現(xiàn)進(jìn)度條暫停、停止、重新開始、繼續(xù)功能
具體代碼如下:
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>...</title> <!--在IE瀏覽器中運(yùn)行最新的渲染模式--> <meta http-equiv="X-UA-Compatible" content="IE-Edge"> <!--初始化移動(dòng)瀏覽器顯示--> <meta name="viewport" content="width-device-width,inital-scale=1"> <link rel="external nofollow" rel="stylesheet"> <link rel="stylesheet" type="text/css" href="index.css" rel="external nofollow" > <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ var value = 0; var time = 50; //進(jìn)度條復(fù)位函數(shù) function reset( ) { value = 0 $("#prog").removeClass("progress-bar-success").css("width","0%").text("等待啟動(dòng)"); //setTimeout(increment,5000); } //百分?jǐn)?shù)增加,0-30時(shí)為紅色,30-60為黃色,60-90為藍(lán)色,>90為綠色 function increment( ) { value += 1; $("#prog").css("width",value + "%").text(value + "%"); if (value>=0 && value<=30) { $("#prog").addClass("progress-bar-danger"); } else if (value>=30 && value <=60) { $("#prog").removeClass("progress-bar-danger"); $("#prog").addClass("progress-bar-warning"); } else if (value>=60 && value <=90) { $("#prog").removeClass("progress-bar-warning"); $("#prog").addClass("progress-bar-info"); } else if(value >= 90 && value<100) { $("#prog").removeClass("progress-bar-info"); $("#prog").addClass("progress-bar-success"); } else{ setTimeout(reset,3000); return; } st = setTimeout(increment,time); } increment(); //進(jìn)度條停止與重新開始 $("#stop").click(function () { if ("stop" == $("#stop").val()) { //$("#prog").stop(); clearTimeout(st); $("#prog").css("width","0%").text("等待啟動(dòng)"); $("#stop").val("start").text("重新開始"); } else if ("start" == $("#stop").val()) { increment(); $("#stop").val("stop").text("停止"); } }); //進(jìn)度條暫停與繼續(xù) $("#pause").click(function() { if ("pause" == $("#pause").val()) { //$("#prog").stop(); clearTimeout(st); $("#pause").val("goon").text("繼續(xù)"); } else if ("goon" == $("#pause").val()) { increment(); $("#pause").val("stop").text("暫停"); } }); }); </script> </head> <body> <div class="progress progress-striped active"> <div id="prog" class="progress-bar" role="progressbar" aria-valuenow="" aria-valuemin="0" aria-valuemax="100" > <span id="proglabel">正在啟動(dòng),請(qǐng)稍后......</span> </div> </div> <div class="form-group"> <div class="col-sm-offset-4 col-sm-6"> <button id="pause" class="btn btn-primary" value="pause">暫停</button> <button id="stop" class="btn btn-primary" value="stop">停止</button> <!--<button id="goon" class="btn btn-primary">繼續(xù)<button>--> </div> </div> </body> </html>
PS:關(guān)于bootstrap布局,這里再為大家推薦一款本站的在線可視化布局工具供大家參考使用:
在線bootstrap可視化布局編輯工具:
http://tools.jb51.net/aideddesign/layoutit
希望本文所述對(duì)大家基于bootstrap的程序設(shè)計(jì)有所幫助。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。