Hide scroll to top button when the scrolling stops

Hey,

You need to do exactly the same what you did on video from post above, just use code below instead, and you need to set class on that button “scroll-to-top”.

let isScrolling;
$(window).on('scroll', function() {
    if (isScrolling) {
        clearTimeout(isScrolling);
    }

    // Show the button while scrolling
    $('.scroll-to-top').css("opacity", "1");
    $('.scroll-to-top').css("pointer-events", "auto");

    // Set a timer to hide the button after 300ms of no scrolling
    isScrolling = setTimeout(function() {
        $('.scroll-to-top').css("opacity", "0");
        $('.scroll-to-top').css("pointer-events", "none");
    }, 300); 
});
1 Like