bootstrap+jQuery實現(xiàn)的動態(tài)進度條功能示例
本文實例講述了bootstrap+jQuery實現(xiàn)的動態(tài)進度條功能。分享給大家供大家參考,具體如下:
此款進度條實現(xiàn)的功能:
1.利用了bootstrap的進度條組件。
a.在最外層的<div>中加入class .progress,在里層<div>加入class .progress-bar從而實現(xiàn)基本的進度條。
b.在外層<div>中加入class .progress-striped實現(xiàn)條紋進度條。
c.在內(nèi)層<div>加入class .progress-bar-danger/warning/info/success 從而實現(xiàn)紅色、黃色、藍色、綠色
d.在外層<div>中加入class .active 實現(xiàn)動畫效果
2.利用jQuery對進度條進度進行控制。
0-30時顯示紅色,30-60顯示黃色,60-90顯示綠色,90-100顯示綠色
實現(xiàn)進度條暫停、停止、重新開始、繼續(xù)功能
具體代碼如下:
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>...</title> <!--在IE瀏覽器中運行最新的渲染模式--> <meta http-equiv="X-UA-Compatible" content="IE-Edge"> <!--初始化移動瀏覽器顯示--> <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; //進度條復(fù)位函數(shù) function reset( ) { value = 0 $("#prog").removeClass("progress-bar-success").css("width","0%").text("等待啟動"); //setTimeout(increment,5000); } //百分?jǐn)?shù)增加,0-30時為紅色,30-60為黃色,60-90為藍色,>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(); //進度條停止與重新開始 $("#stop").click(function () { if ("stop" == $("#stop").val()) { //$("#prog").stop(); clearTimeout(st); $("#prog").css("width","0%").text("等待啟動"); $("#stop").val("start").text("重新開始"); } else if ("start" == $("#stop").val()) { increment(); $("#stop").val("stop").text("停止"); } }); //進度條暫停與繼續(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" style="width:0%;"> <span id="proglabel">正在啟動,請稍后......</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
希望本文所述對大家基于bootstrap的程序設(shè)計有所幫助。
- Bootstrap每天必學(xué)之進度條
- BootStrap Progressbar 實現(xiàn)大文件上傳的進度條的實例代碼
- bootstrap實現(xiàn)動態(tài)進度條效果
- BootStrap 實現(xiàn)各種樣式的進度條效果
- BootStrap初學(xué)者對彈出框和進度條的使用感覺
- Spring Boot+AngularJS+BootStrap實現(xiàn)進度條示例代碼
- bootstrap多種樣式進度條展示
- BootStrap組件之進度條的基本用法
- Bootstrap實現(xiàn)各種進度條樣式詳解
- Bootstrap進度條實現(xiàn)代碼解析
- jquery 簡單的進度條實現(xiàn)代碼
- 分享8款優(yōu)秀的 jQuery 加載動畫和進度條插件
相關(guān)文章
JavaScript實現(xiàn)簡易的天數(shù)計算器實例【附demo源碼下載】
這篇文章主要介紹了JavaScript實現(xiàn)簡易的天數(shù)計算器,結(jié)合實例形式分析了javascript日期與時間計算的相關(guān)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-01-01layui table動態(tài)表頭 改變表格頭部 重新加載表格的方法
今天小編就為大家分享一篇layui table動態(tài)表頭 改變表格頭部 重新加載表格的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09如何在uni-app使用微軟的文字轉(zhuǎn)語音服務(wù)
有了語音識別,交流就會變得很簡單,下面這篇文章主要給大家介紹了關(guān)于如何在uni-app使用微軟的文字轉(zhuǎn)語音服務(wù)的相關(guān)資料,需要的朋友可以參考下2022-06-06