美文网首页Web前端之路
Bootstrap组件 - 进度条

Bootstrap组件 - 进度条

作者: 蝴蝶结199007 | 来源:发表于2017-06-16 14:05 被阅读91次

    知识点

    进度条组件使用了 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-barwidth值,否则状态条不会显现。
    如果需要显示进度条进度提示,直接除去 <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>
    

    根据情境变化效果
    进度条组件使用与按钮和警告框相同的类,根据不同情境展现相应的效果。
    .progress-bar-success
    .progress-bar-info
    .progress-bar-warning
    .progress-bar-danger

    条纹效果

    1. 为父级 .progress 添加 .progress-striped
    2. 或者为 .progress-bar 添加 .progress-bar-striped

    动画效果
    .progress-bar-striped 添加 .active 类,使其呈现出由右向左运动的动画效果。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>
    

    相关文章

      网友评论

        本文标题:Bootstrap组件 - 进度条

        本文链接:https://www.haomeiwen.com/subject/gripqxtx.html