进度条(Progressbar)


jQuery UI 实例 - 进度条(Progressbar)

显示一个确定的或不确定的进程状态。

如需了解更多有关 progressbar 部件的细节,请查看 API 文档 进度条部件(Progressbar Widget)。

默认功能

默认的确定的进度条。

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="utf-8">
  5.   <title>jQuery UI 进度条(Progressbar) - 默认功能</title>
  6.   <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  7.   <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  8.   <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  9.   <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
  10.   <script>
  11.   $(function() {
  12.     $( "#progressbar" ).progressbar({
  13.       value: 37
  14.     });
  15.   });
  16.   </script>
  17. </head>
  18. <body>
  19.  
  20. <div id="progressbar"></div>
  21.  
  22.  
  23. </body>
  24. </html>

自定义标签

自定义更新的标签。

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="utf-8">
  5.   <title>jQuery UI 进度条(Progressbar) - 自定义标签</title>
  6.   <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  7.   <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  8.   <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  9.   <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
  10.   <style>
  11.   .ui-progressbar {
  12.     position: relative;
  13.   }
  14.   .progress-label {
  15.     position: absolute;
  16.     left: 50%;
  17.     top: 4px;
  18.     font-weight: bold;
  19.     text-shadow: 1px 1px 0 #fff;
  20.   }
  21.   </style>
  22.   <script>
  23.   $(function() {
  24.     var progressbar = $( "#progressbar" ),
  25.       progressLabel = $( ".progress-label" );
  26.  
  27.     progressbar.progressbar({
  28.       value: false,
  29.       change: function() {
  30.         progressLabel.text( progressbar.progressbar( "value" ) + "%" );
  31.       },
  32.       complete: function() {
  33.         progressLabel.text( "完成!" );
  34.       }
  35.     });
  36.  
  37.     function progress() {
  38.       var val = progressbar.progressbar( "value" ) || 0;
  39.  
  40.       progressbar.progressbar( "value", val + 1 );
  41.  
  42.       if ( val < 99 ) {
  43.         setTimeout( progress, 100 );
  44.       }
  45.     }
  46.  
  47.     setTimeout( progress, 3000 );
  48.   });
  49.   </script>
  50. </head>
  51. <body>
  52.  
  53. <div id="progressbar"><div class="progress-label">加载...</div></div>
  54.  
  55.  
  56. </body>
  57. </html>

不确定的值

不确定的进度条,并可在确定和不确定的样式之间切换。

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="utf-8">
  5.   <title>jQuery UI 进度条(Progressbar) - 不确定的值</title>
  6.   <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  7.   <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  8.   <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  9.   <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
  10.   <script>
  11.   $(function() {
  12.     $( "#progressbar" ).progressbar({
  13.       value: false
  14.     });
  15.     $( "button" ).on( "click", function( event ) {
  16.       var target = $( event.target ),
  17.         progressbar = $( "#progressbar" ),
  18.         progressbarValue = progressbar.find( ".ui-progressbar-value" );
  19.  
  20.       if ( target.is( "#numButton" ) ) {
  21.         progressbar.progressbar( "option", {
  22.           value: Math.floor( Math.random() * 100 )
  23.         });
  24.       } else if ( target.is( "#colorButton" ) ) {
  25.         progressbarValue.css({
  26.           "background": '#' + Math.floor( Math.random() * 16777215 ).toString( 16 )
  27.         });
  28.       } else if ( target.is( "#falseButton" ) ) {
  29.         progressbar.progressbar( "option", "value", false );
  30.       }
  31.     });
  32.   });
  33.   </script>
  34.   <style>
  35.   #progressbar .ui-progressbar-value {
  36.     background-color: #ccc;
  37.   }
  38.   </style>
  39. </head>
  40. <body>
  41.  
  42. <div id="progressbar"></div>
  43. <button id="numButton">随机值 - 确定</button>
  44. <button id="falseButton">不确定</button>
  45. <button id="colorButton">随机颜色</button>
  46.  
  47.  
  48. </body>
  49. </html>