Bootstrap Progressbar Affix可以工作,但仍然在所有其他组件下

时间:2016-10-26 03:24:58

标签: twitter-bootstrap affix

期望的结果: 我使用了一个进度条,我希望在向下滚动时保持可见。

已采取的措施: 我在包含进度条组件的整个部分使用了Affix。

当前结果: 它似乎有效,但滚动条位于所有其他组件之下,因此在滚动时会消失在它们后面。

<html>

  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
      .affix {
          top: 1;
          width: 100%;
      }

      .affix + .container-fluid {
          padding-top: 70px;
      }
    </style>
    <script>
      $(document).ready(function(){

              });
    </script>
  </head>

  <body>
    <div class="container">
      <h2 class="text-center">Title</h2>
      <div class="panel-group" id="accordion"></div>
    </div>
    <div class="section" data-spy="affix" data-offset-top="20">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <div class="progress" id="progressbarid">
              <div class="progress-bar" role="progressbar" style="width: 0%;"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="section">
      <div class="container">
        <div class="row">
          <div class="col-md-12"></div>
        </div>
      </div>
    </div>

    <div class="section">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <div class="panel panel-primary" id="keystone-sectionid">
              <div class="panel-heading">
                <h3 class="panel-title">Section1</h3>
              </div>
              <div class="panel-body"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="section">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <div class="panel panel-primary" id="compute-sectionid"></div>
            <div class="panel panel-primary" id="glance-sectionid">
              <div class="panel-heading">
                <h3 class="panel-title">Section2</h3>
              </div>
              <div class="panel-body"></div>
            </div>
            <div class="panel panel-primary" id="cinder-sectionid">
              <div class="panel-heading">
                <h3 class="panel-title">Section3</h3>
              </div>
              <div class="panel-body"></div>
            </div>
            <div class="panel panel-primary" id="heat-sectionid">
              <div class="panel-heading">
                <h3 class="panel-title">Section4</h3>
              </div>
              <div class="panel-body"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </body>

</html>

以下是jsfiddle中的行为:
https://jsfiddle.net/AJNOURI/07ckpj1h/

1 个答案:

答案 0 :(得分:0)

应该使用CSS Stacking Elements in Layers Using z-index Property z-index

  .affix {
      top: 1;
      width: 100%;
      z-index: 1;
  }

更新 https://jsfiddle.net/AJNOURI/07ckpj1h/2/