知識點
進度條組件使用了 CSS3 的 transition 和 animation 屬性來完成一些特效稠氮。這些特性在 Internet Explorer 9 或以下版本中、Firefox 的老版本中沒有被支持次兆。Opera 12 不支持 animation 屬性。
基本實例
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuemax="100" aria-valuemin="0" aria-valuenow="60" style="width:60%;">
<span class="sr-only">60%</span>
</div>
</div>
設置了 aria-valuenow="60"
芥炭,還需要設置 .progress-bar
的 width
值恃慧,否則狀態(tài)條不會顯現(xiàn)。
如果需要顯示進度條進度提示彪薛,直接除去 <span class="sr-only">60%</span>
的包裹怠蹂。
在展示很低的百分比時善延,如果需要讓文本提示能夠清晰可見城侧,可以為進度條設置 min-width
屬性。
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="min-width: 2em;">
0%
</div>
</div>
根據(jù)情境變化效果
進度條組件使用與按鈕和警告框相同的類豆茫,根據(jù)不同情境展現(xiàn)相應的效果屋摇。
.progress-bar-success
.progress-bar-info
.progress-bar-warning
.progress-bar-danger
條紋效果
- 為父級
.progress
添加.progress-striped
類 - 或者為
.progress-bar
添加.progress-bar-striped
類
動畫效果
為 .progress-bar-striped
添加 .active
類,使其呈現(xiàn)出由右向左運動的動畫效果火脉。IE9 及更低版本的瀏覽器不支持。
實踐
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="Resource-type" content="Document"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>組件-進度條</title>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<style>
<!--
.line{border-top:1px solid #afd9ee;margin:20px 0;}
-->
</style>
</head>
<body>
<div class="container">
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuemax="100" aria-valuemin="0" aria-valuenow="60" style="width:60%;">
<span class="sr-only">60%</span>
</div>
</div>
<!--min-width-->
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="min-width: 2em;">
0%
</div>
</div>
<!--情景顏色變化-->
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuemax="100" aria-valuemin="0" aria-valuenow="20" style="width:20%;">
<span class="sr-only">progress-bar-success</span>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-info" role="progressbar" aria-valuemax="100" aria-valuemin="0" aria-valuenow="40" style="width:40%;">
<span class="sr-only">progress-bar-info</span>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuemax="100" aria-valuemin="0" aria-valuenow="60" style="width:60%;">
<span class="sr-only">progress-bar-warning</span>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuemax="100" aria-valuemin="0" aria-valuenow="80" style="width:80%;">
<span class="sr-only">progress-bar-danger</span>
</div>
</div>
<!--條紋效果的進度條-->
<div class="progress">
<div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 20%">
<span class="sr-only">progress-bar-striped</span>
</div>
</div>
<div class="progress progress-striped">
<div class="progress-bar" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 40%">
<span class="sr-only">progress-striped</span>
</div>
</div>
<!--條紋的動畫效果-->
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width:60%">
<span class="sr-only">progress-bar-striped添加active</span>
</div>
</div>
<!--堆疊-->
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width:20%">
<span class="sr-only">progress-bar-striped添加active</span>
</div>
<div class="progress-bar progress-bar-info progress-bar-striped active" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" style="width:30%">
<span class="sr-only">progress-bar-striped添加active</span>
</div>
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">
<span class="sr-only">progress-bar-striped添加active</span>
</div>
</div>
</div>
</body>
</html>