简介
在本教程中,您将看到如何使用 Bootstrap 创建加载、重定向或动作状态的进度条。
基本的、条纹的和动画的进度条实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Example of using default thumbnails from ziqiangxuetang.com</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="Example of using default thumbnails from ziqiangxuetang.com"> <meta name="author" content=""> <!-- Le styles --> <link href="../bootstrap/bootstrap-2.0.3.css" rel="stylesheet"> <link href="../bootstrap/twitter-bootstrap-v2/docs/assets/css/example-fixed-layout.css" rel="stylesheet"> <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements --> <!--[if lt IE 9]> <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <!-- Le fav and touch icons --> <link rel="shortcut icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/favicon.ico"> <link rel="apple-touch-icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="72x72" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-72x72.png"> <link rel="apple-touch-icon" sizes="114x114" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-114x114.png"> </head> <body> <div class="container"> <div class="row"> <div class="span4"> <h3>A basic Progress Bar with vertical gradient</h3> <div class="progress"> <div class="bar" style="width: 60%;"></div> </div> <h3>A striped Progress Bar, uses gradient to create a striped effect</h3> <div class="progress progress-striped"> <div class="bar" style="width: 60%;"></div> </div> <h3>An animated Progress Bar</h3> <div class="progress progress-striped active"> <div class="bar" style="width: 50%;"></div> </div> </div> </div> <hr> </div> <!-- /container --> </body> </html>
请注意,如果要显示第三种进度条,请添加 '.active' class 来让它具有运动感。Bootstrap 使用 css3 过渡效果创建这个动画。您也可以通过 JavaScript 动态地调整进度条的宽度。这样,就可以掌握进度行为。
在创建进度条时,您可以使用其他的颜色。
带有其他颜色的进度条实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Example of Progress Bars with additional colors using Bootstrap</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="Example of Progress Bars with additional colors using Bootstrap, created by ziqiangxuetang"> <meta name="author" content=""> <!-- Le styles --> <link href="../bootstrap/bootstrap-2.0.3.css" rel="stylesheet"> <link href="../bootstrap/twitter-bootstrap-v2/docs/assets/css/example-fixed-layout.css" rel="stylesheet"> <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements --> <!--[if lt IE 9]> <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <!-- Le fav and touch icons --> <link rel="shortcut icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/favicon.ico"> <link rel="apple-touch-icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="72x72" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-72x72.png"> <link rel="apple-touch-icon" sizes="114x114" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-114x114.png"> </head> <body> <div class="container"> <div class="row"> <div class="span4"> <h3>Progress bars may also have additional colors</h3> <div class="progress progress-info progress-striped" style="margin-bottom: 9px;"> <div class="bar" style="width: 20%"></div> </div> <div class="progress progress-success progress-striped active" style="margin-bottom: 9px;"> <div class="bar" style="width: 40%"></div> </div> <div class="progress progress-warning progress-striped" style="margin-bottom: 9px;"> <div class="bar" style="width: 60%"></div> </div> <div class="progress progress-danger progress-striped active" style="margin-bottom: 9px;"> <div class="bar" style="width: 80%"></div> </div> </div> </div> </div> <hr> </div> <!-- /container --> </body> </html>
浏览器支持
我们已经在不同的浏览器中测试了上面的两个实例。我们发现,在 Firefox 12 和 Chrome 19.0.1084.52 中能正常显示,但是在 Opera 11.62 中不能显示动画效果,即便您可以看到条纹和梯度。在 Internet Explorer 8 中,所有的显示效果都不佳,没有动画,也没有条纹和梯度。