Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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,我有一个固定的导航条,向下滚动页面时,导航条会消失,向上滚动页面时,导航条会重新出现,这一切都很好,但我注意到,如果我快速移动,比如说20次,导航条就会消失。它没有时间这么做,似乎在存储计数,然后将继续闪烁该数量的时间。我怎样才能阻止这一切 这是我的密码: <script type="text/javascript"> var previousScroll = 0, headerOrgOffset = $('#centre').height(); $('header').heigh

我有一个固定的导航条,向下滚动页面时,导航条会消失,向上滚动页面时,导航条会重新出现,这一切都很好,但我注意到,如果我快速移动,比如说20次,导航条就会消失。它没有时间这么做,似乎在存储计数,然后将继续闪烁该数量的时间。我怎样才能阻止这一切

这是我的密码:

<script type="text/javascript">
var previousScroll = 0,
headerOrgOffset = $('#centre').height();

$('header').height($('#centre').height());

$(window).scroll(function () {
var currentScroll = $(this).scrollTop();
if (currentScroll > headerOrgOffset) {
    if (currentScroll > previousScroll) {
        $('header').fadeOut();
    } else {
        $('header').fadeIn();
    }
} else {
        $('header').fadeIn();
}
previousScroll = currentScroll;
});
</script>

<style type="css/text">
header {
width:100%;
height:86px;
background:#ffffff;
top:0;
left:0;
right:0;
position:fixed;
z-index: 1000;
display:block;
border-bottom: solid 1px #eee;
}

#centre {
width:960px;
height:86px;
margin-left:auto;
margin-right:auto;
background:#ffffff;
}
</style>

<header>
    <div id="centre">Nav</div>
</header>

这是一个被称为去Bouncing的概念。在特定时间范围内的任何重复操作基本上都会被忽略。在下面的代码中,doSomething方法仅在上次滚动事件发生500毫秒后调用

function doSomething() {
   // do some really cool stuff
}

var timer;
$(window).scroll(function () {
    clearTimeout(timer);
    timer = setTimeout(doSomething, 500);
});

我似乎无法用上面的代码复制您的问题。你能帮我寄封信吗?像JSFIDLE或CodePen这样的代码提琴也会很有帮助:嗨,Ryan,谢谢你的回答。你还知道我如何防止导航在页面开始时立即消失吗?所以,当它达到150像素的时候,它就消失了?你需要自己处理这个问题,因为这与这个问题是分开的。请随意尝试一下,如果您有问题,可以创建一个JSFIDLE并打开一个新问题。