如何让两个导航条一个接一个地保持静止并且还可以捕捉到顶部?

时间:2016-04-12 10:49:35

标签: html css twitter-bootstrap

我有2个导航栏,我希望它们最初位于页面顶部但滚动时我希望第一个带有品牌形象的导航栏折叠掉,带有列表链接的第二个导航栏会捕捉到第一个导航栏最初的页面顶部。有谁知道我怎么做到这一点?这是一张供参考的图片:enter image description here

HTML:

<!----- Navbar ----->
<nav class="navbar navbar-default navbar-collapse">
  <div class="container">
    <div class="navbar-header">
      <div class="navbar-header">
        <img id="brand-image" alt="DEVO Logo" src="/Applications/MAMP/htdocs/D0.1/images/DEVOorig.png"/>
      </div>
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
  </div>
  <div class="collapse navbar-collapse" id="myNavbar">
    <ul class="nav navbar-nav navbar-right">
      <li><a href="#"></a></li>
      <li><a href="#"><span class="glyphicon glyphicon-user"></span></a></li>
      <li><a href="#"><span class="glyphicon glyphicon-shopping-cart"></span></a></li>
      <li>
        <div class="form-group form-inline">
          <input type="text" class="form-control" placeholder="Search products..">
        </div>
        <button type="submit" class="btn btn-secondary" id="product-search-btn"><span class="glyphicon glyphicon-search"></button>
      </li>
    </ul>
  </div>
</div>

<nav class="navbar navbar-inverse navbar-fixed-top" id="info-head">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="#">Tobi's Site</a>
  </div>
  <div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav">
        <li><a href="#section1">About Us</a></li>
        <li><a href="#section2">FAQ's</a></li>
        <li><a href="#section3">Contact Us</a></li>
        <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Work With Us <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#section41">Drivers</a></li>
            <li><a href="#section42">Partners</a></li>
            <li><a href="#section43">In House</a></li>
          </ul>
        </li>
        <li><a href="#section5">T's & C's</a></li>
        <li><a href="#section5">Privacy Policy</a></li>
      </ul>
     </div>
  </div>
  </div>
</nav>

1 个答案:

答案 0 :(得分:4)

滚动页面时,使用Bootstrap affix组件固定第二个导航栏。然后添加affix类的CSS,以便在导航栏固定到顶部时对其进行定位。

$('#nav2').affix({
      offset: {
        top: 50
      }
}); 

2个导航栏示例:http://codeply.com/go/hi6zhTU4h2