In my site, I'm trying to detect if users scroll up; the site should go to the first page, and vice versa.
I have two pages, each page has a full screen (100vh), and both are in the middle of the screen, and I want to keep both of them in the middle all the time. If the user scrolls down, the site should go to the button.
I tried to detect if user scroll by event listener and stop it and scroll then start it again but I don't understand what happened.
This my code
var position = $(window).scrollTop();
$(window).scroll(function abc() {
$(window).off("scroll");
var scroll = $(window).scrollTop();
if (scroll > position) {
console.log("scrollDown");
$(document).scrollTop($(document).height());
} else {
console.log("scrollUp");
$(document).scrollTop(0);
}
position = scroll;
$(window).on("scroll", abc);
});