I\'m designing a very simple web page (HTML only), the only \"feature\" I want to implement is to do something when the user scrolls down the page, is there a way to capture
Here is my solution in pure JavaScript, be careful the only problem is that it is executed a lot of times. Sorry for the spelling I use google translate, I am french ;)
var scrollBefore = 0;
window.addEventListener('scroll',function(e){
const scrolled = window.scrollY;
if(scrollBefore > scrolled){
console.log("ScrollUP");
scrollBefore = scrolled;
//Desired action
}else{
scrollBefore = scrolled;
console.log("ScrollDOWN");
//Desired action
}
})