Bootstrap 3 - 带有固定SUBNAV的STATIC NAVBAR变得粘稠?

时间:2014-08-13 00:15:40

标签: twitter-bootstrap-3 navbar

在这里使用Bootstrap 3。我正在尝试制作一个倒置的NAVBAR,它是“静态的”(当用户向下滚动时上升),其下方加载的SUBNAV将在到达屏幕顶部时变为“固定”状态。如果用户再次向上滚动,则NAVBAR应该返回。我不确定你会怎么称呼它。

这是一个非工作的模型...

http://jsbin.com/xagetaloyago/2/edit

1 个答案:

答案 0 :(得分:6)

试试这个例子..

http://www.bootply.com/HqtmsMHmuu

您需要在subnav上使用Bootstrap的词缀组件,并在.affix应用于子区域时相应地更新CSS。

<强> CSS

.navbar {
    margin-bottom:0;
}

.subnav {
   margin:0;
  top: 0px;
  z-index: 1020;
  background-color: rgb(247,247,247); 
  border-bottom: 1px solid #E1E1E1;
  padding: 8px 0px 0px 0px;
}

.subnav.affix {
    position: fixed;
    top: 0;
    width: 100%;
    z-index:10;
}

<强> HTML

<div id="navtop">
  <div class="navbar navbar-inverse navbar-static-top">
    <div class="container">
      <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
      <a href="#" class="navbar-brand">Brand</a>
      <a class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="glyphicon glyphicon-bar"></span>
        <span class="glyphicon glyphicon-bar"></span>
        <span class="glyphicon glyphicon-bar"></span>
      </a>
      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav">
          <li><a href="#">Link</a></li>
          <li><a href="#">Link</a></li>
        </ul>
        <ul class="nav pull-right navbar-nav">
          <li>
            <form class="navbar-form">
              <input type="text" class="form-control" placeholder="Search">
              <button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
            </form>
          </li>
          <li>
            <a href="#"><span class="badge">2</span></a>
          </li>
        </ul>
      </div>        
    </div>
  </div><!-- /.navbar -->
</div>          

<!-- subnav here -->
<div class="navbar subnav" role="navigation">
    <div class="navbar-inner">
        <div class="container"> 
        <ul class="pager subnav-pager"> 
            <div class="btn-group-wrap">
                <button type="button" class="btn btn-success">sub 1</button>
                <button type="button" class="btn btn-success">sub 2</button>
             </div>         
        </ul>   
</div>
</div>
</div>

<强> JS

$('.subnav').affix({
      offset: {
        top: $('#navtop').height()
      }
});