前面在介绍jQuery 入门教程(20): jQuery UI 基本工作过程时简要介绍过Progessbar用法。
在使用进度条时,如果可以预知进度的大小,可以设置Max大小,如果对于一些无法预约时间比如下载文件可以使用“中间状态”的状态条。
基本用法
5 |
< title >jQuery UI Demos</ title > |
6 |
< link rel = "stylesheet" href = "themes/trontastic/jquery-ui.css" /> |
7 |
< script src = "scripts/jquery-1.9.1.js" ></ script > |
8 |
< script src = "scripts/jquery-ui-1.10.1.custom.js" ></ script > |
11 |
$("#progressbar").progressbar({ |
19 |
< div id = "progressbar" ></ div > |
显示进度
可以在显示进度条的同时显示当前的百分比(实际上可以显示任意文字),这是通过两个嵌套的div元素来实现,本例使用一个定时器来模拟进度条的动态效果。
5 |
< title >jQuery UI Demos</ title > |
6 |
< link rel = "stylesheet" href = "themes/trontastic/jquery-ui.css" /> |
7 |
< script src = "scripts/jquery-1.9.1.js" ></ script > |
8 |
< script src = "scripts/jquery-ui-1.10.1.custom.js" ></ script > |
15 |
text-shadow: 1px 1px 0 #fff; |
20 |
var progressbar = $("#progressbar"), |
21 |
progressLabel = $(".progress-label"); |
23 |
progressbar.progressbar({ |
26 |
progressLabel.text(progressbar.progressbar("value") + "%"); |
28 |
complete: function () { |
29 |
progressLabel.text("Complete!"); |
34 |
var val = progressbar.progressbar("value") || 0; |
36 |
progressbar.progressbar("value", val + 1); |
39 |
setTimeout(progress, 100); |
43 |
setTimeout(progress, 3000); |
50 |
< div class = "progress-label" >Loading...</ div > |
![20130320011](http://www.imobilebbs.com/wordpress/wp-content/uploads/2013/03/20130320011.png)
“中间过渡”状态条
可以通过设置 value=false 将进度条显示为“过渡”状态的进度条,此外也可以通过配置来修改进度条的颜色。
5 |
< title >jQuery UI Demos</ title > |
6 |
< link rel = "stylesheet" href = "themes/base/jquery-ui.css" /> |
7 |
< script src = "scripts/jquery-1.9.1.js" ></ script > |
8 |
< script src = "scripts/jquery-ui-1.10.1.custom.js" ></ script > |
11 |
$("#progressbar").progressbar({ |
14 |
$("button").on("click", function (event) { |
15 |
var target = $(event.target), |
16 |
progressbar = $("#progressbar"), |
18 |
= progressbar.find(".ui-progressbar-value"); |
20 |
if (target.is("#numButton")) { |
21 |
progressbar.progressbar("option", { |
22 |
value: Math.floor(Math.random() * 100) |
24 |
} else if (target.is("#colorButton")) { |
25 |
progressbarValue.css({ |
27 |
+ Math.floor(Math.random() |
28 |
* 16777215).toString(16) |
30 |
} else if (target.is("#falseButton")) { |
31 |
progressbar.progressbar("option", |
38 |
#progressbar .ui-progressbar-value { |
39 |
background-color: #ccc; |
45 |
< div id = "progressbar" ></ div > |
46 |
< button id = "numButton" >Random Value - Determinate</ button > |
47 |
< button id = "falseButton" >Indeterminate</ button > |
48 |
< button id = "colorButton" >Random Color</ button > |
![20130320012](http://www.imobilebbs.com/wordpress/wp-content/uploads/2013/03/20130320012.png)