(jQuery) Scrolling event. I want to scroll the document to the specified point if the user scrolls the page

I want to implement a scroll function. Therefore, the default value for scrolling is disabled. And if the user uses the scroll button, I want it to be configured the way I want. How can I implement this feature? window.scrollTop does not work. I tried many different methods, but all of them did not work.

$(window).scroll(function() {
        $(body).scrollTop = 3000px;
})
+3
source share
2 answers

The property scrollTopallows only an integer (not pixels). Lower pxit and it should be good.

$(window).scroll(function() {
    $('body').get(0).scrollTop = 3000; // note that this does only work if body has overflow
    // if it hasn't, use window instead
});
+6
source
+3

Source: https://habr.com/ru/post/1707493/


All Articles