I got a code that detects when the mouse scrolls, but it is giving 2 results instead of one, when I roll the mouse only once, the console.log is executed two or more times, there is a way to limit it with only one output at a time?
let ScrollPosition = 0
$w.onReady(function () {
setInterval(responsifyScroll, 200);
});
function responsifyScroll() {
wixWindow.getBoundingRect()
.then((windowSizeInfo) => {
//check for scrollY
if (ScrollPosition !== windowSizeInfo.scroll.y) {
//console.log(ScrollPosition)
//check if scrolling down
if (ScrollPosition < windowSizeInfo.scroll.y) {
console.log("DOWN")
}
//check if scrolling up
else if (ScrollPosition > windowSizeInfo.scroll.y) {
console.log("UP")
}
//set new scrollY
ScrollPosition = windowSizeInfo.scroll.y;
//console.log(ScrollPosition)
}
});
}
code by: calum:
https://www.wix.com/corvid/forum/community-discussion/help-me-write-this-mouse-wheel-scroll-logic