如何使导航栏出现在页面的特定部分? (bootstrap 也是)

How to make a navbar appear in certain section of the page? (bootstrap too)

我正在制作一个网站,当他处于移动模式 (> 767px) 时会看到一个导航栏。我已经知道了,但是我希望这个导航栏只出现在第 1 部分之后。

默认情况下,导航栏始终显示。我希望它仅在我看到第 2 节时出现。

请看下面的例子:

示例:http://jsfiddle.net/gtw7375/3zc5Ltzp/

HTML:

<nav class="navbar navbar-default navbar-fixed-bottom visible-xs">
  <div class="container-fluid"> 

    <div class="navbar-header">
         <!-- <a class="navbar-brand" href="#">LOGO PSTCH</a> </div> -->


    <div class="collapse navbar-collapse visible-xs" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
       <li><a  href="#" data-toggle="modal" data-target="#myModal1" data-direction="bottom"> About</a></li>
       <li><a  href="#" data-toggle="modal" data-target="#myModal2" data-direction='bottom'> Sobre </a></li>
       <li><a  href="#" data-toggle="modal" data-target="#myModal3" data-direction='bottom'> Contact </a></li>


      </ul>    
    </div>
    </div>  
  </div> 
</nav>

 <div id="logo"> 

            <center>
                            <a href="#desce" class="page-scroll  btn btn-xl">SECTION 1</a>
            </center>
  </div>

  <div id="content">

    <p> SECTION 2  </p>

      <p> The navbar will appear here down/hereafter!</p>
  </div>

CSS:

html, body {
    height:100%;
    padding:0;
    margin:0;

}


#logo{
            background: black;
            width: 100%;
            height: 100%;          


}

#content {
        border: 1px solid black;
        width: 100%;
        height: 50%;
}

.navbar .nav  li{
    float:none;
    display:inline-block;
    *display:inline; /* Internet Explorer 7 compatibility */
    *zoom:1;
    vertical-align: bottom;

}


.navbar .navbar-collapse {
  text-align: center;
}

我该怎么做?

我不太明白你想用你的代码做什么。

<div id="box01">
     <p>This will be hidden, only visible after 767px.</p>
</div>

.box01 {
    display: none;
}
@media screen and (max-width : 767px) {
    .box01 {
        display: block;
    }
}

如果您正在使用 JQuery,您可以监听 window 的滚动事件,检查它是否滚动到元素的顶部偏移量之外并采取相应的措施。以下是使用 JQuery 插件的 Javascript 代码。

$(document).ready(function(){

  $(".navbar").hide(); //Hide the navigation bar first

    $(window).scroll(function () {  //Listen for the window's scroll event
        if (isScrolledAfterElement("#content")) { //if it has scrolled beyond the #content elment
            $('.navbar').fadeIn();  //Show the navigation bar
        } else {
            $('.navbar').fadeOut(); //Else hide it
        }
    });

    //Function that returns true if the window has scrolled beyond the given element
    function isScrolledAfterElement(elem) {
        var $elem = $(elem);
        var $window = $(window);

        var docViewTop = $window.scrollTop();
        var docViewBottom = docViewTop + $window.height();

        var elemTop = $elem.offset().top;

        return elemTop <= docViewBottom;
    }
});

您可以在此 jsfiddle 中看到实际效果。我从导航栏中删除了 visible-xs class 并且还在 中添加了 margin-bottom 属性#logo 元素使所有用户都能注意到效果(您不必对您的项目执行此操作)。