Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 滚动后如何停止导航栏?_Javascript_Html_Css - Fatal编程技术网

Javascript 滚动后如何停止导航栏?

Javascript 滚动后如何停止导航栏?,javascript,html,css,Javascript,Html,Css,HTML: js文件: .navigation-bar { background: black; width: 100%; margin: 0px; height: 70px; position: sticky; } .f-nav{ /* To fix main menu container */ z-index: 9999; position: fixed; left: 0; top: 0; width: 100

HTML:

js文件:

.navigation-bar {
    background: black;
    width: 100%;
    margin: 0px;
    height: 70px;
    position: sticky;
}
.f-nav{  /* To fix main menu container */
    z-index: 9999;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
}
.item {
    float: left;
    width: 20%;
    height: 100%;
    color: white;
    text-align: center;
    font-family: ‘Lucida Sans Unicode’, ‘Lucida Grande’, sans-serif;
    font-size: 26px;
    font-weight: 100;
    padding-top: 20px;
}
这是我的代码,但它不起作用。我不知道当导航栏到达顶部时如何停止。我认为代码还可以,但我不知道为什么它不起作用。


$("document").ready(function ($) {
    var nav = $('.navigation-bar');
    $(window).scroll(function () {
        if ($(this).scrollTop() > 125) {
            nav.addClass("f-nav");
        } else {
            nav.removeClass("f-nav");
        }
    });
});
$(文档).ready(函数(){ $(窗口).bind('scroll',function(){ var navHeight=$(窗口).height()-70; 如果($(窗口).scrollTop()>navHeight){ $('nav').addClass('fixed'); } 否则{ $('nav').removeClass('fixed'); } }); }); .固定{ 位置:固定; 排名:0; 高度:70像素; z指数:1; }



有效,有什么问题吗?@Zee我想他想要的是:当用户停止滚动时,导航栏显示:无谢谢,这帮了大忙
$("document").ready(function ($) {
    var nav = $('.navigation-bar');
    $(window).scroll(function () {
        if ($(this).scrollTop() > 125) {
            nav.addClass("f-nav");
        } else {
            nav.removeClass("f-nav");
        }
    });
});
    <script>
       $(document).ready(function(){
           $(window).bind('scroll', function() {
           var navHeight = $( window ).height() - 70;
                 if ($(window).scrollTop() > navHeight) {
                     $('nav').addClass('fixed');
                 }
                 else {
                     $('nav').removeClass('fixed');
                 }
            });
        });
    </script>
.fixed {
    position: fixed; 
    top: 0; 
    height: 70px; 
    z-index: 1;
}
<nav>
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Team</a></li>
        <li><a href="#">Contact</a></li>
    </ul>
</nav>