简体   繁体   English

停止滚动时如何停止菜单

[英]how to stop menu when you stop scrolling

I can't figure out how to stop menu when you stop scrolling. 当你停止滚动时,我无法弄清楚如何停止菜单。 When you scroll down menu has to hide and show only when stop scrolling or scrolling up. 当您向下滚动菜单时,只有在停止滚动或向上滚动时才隐藏和显示。 My code work only when you scroll up, I would appreciate if you help me. 我的代码仅在您向上滚动时才起作用,如果您帮助我,我将不胜感激。

js: JS:

$(window).scroll({
    previousTop: 0
    }, 
    function () {
        var currentTop = $(window).scrollTop();
        if (currentTop < this.previousTop) {
            $("header").css("display", "none");
        } else {
        $("header").css("display", "block");
    }
    this.previousTop = currentTop;
});

The problem is you're only checking for when the currentTop is less than the previousTop . 问题是你只检查currentTop小于previousTop That would be only when going up. 只有在上升时才会这样。

Really, if you want to trigger it any time you're scrolling, you need to just do currentTop != previousTop , which will work in both directions. 真的,如果你想在你滚动的任何时候触发它,你需要只做currentTop != previousTop ,它将在两个方向上工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM