简体   繁体   中英

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:

$(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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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