Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop ScrollTop function when user scrolls jquery

How can i stop the scrollTop function when the user scrolls himself? If i scroll now while the scrollTop function the whole scrolling glitches out.

        $(document).ready(function (){
            $(".header-arrow-down").click(function (){
                $('html, body').animate({
                    scrollTop: $(".page-1").offset().top
                }, 1000);
            });
            $("body").scroll(function() {
                alert("scrolling");
            });
        });

I tried this so far but the alert scrolling isnt showing up for me and i can't find a solution on google so im asking it here.

I hope someone knows how to fix this thanks!

like image 986
Stefan Avatar asked Jun 26 '26 18:06

Stefan


1 Answers

you need to unbind or stop the animation when user scrolls, sth like

$("html, body").bind("scroll mousedown DOMMouseScroll mousewheel keyup", function(){
    $('html, body').stop();
});
like image 143
john Smith Avatar answered Jun 29 '26 08:06

john Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!