I'm experimenting with incrementing a variable based on whether someone scrolls down or up the page.
The event triggers each time you scroll in either direction, but the value only increases by one. Can anyone suggest a reason for this behavior?
window.addEventListener("wheel", function (e) {
const y = e.deltaY;
let scrollIndex = 0;
if (y > 0) {
scrollIndex++;
} else {
scrollIndex--;
}
console.log(`Scroll index: ${scrollIndex}`);
});