So I have this code that upon using a mouse wheel or a touchpad changes the view to the next div in the array of sections. However, when I use the touchpad it does not work properly since at every scroll the index changes. How can I add a delay so that every usage of mouse wheel or touchpad is counted as one scroll. Any suggestions ?
const MainNavigation = () => {
let index = 0;
window.addEventListener("wheel", function (event) {
if (event.deltaY < 0) {
--index;
} else if (event.deltaY > 0) {
++index;
}
scrollToSection();
});
const scrollToSection = () => {
if (index < 0 || index > 2) {
index = 0;
}
console.log(index);
sections[index].scrollIntoView({ behavior: "smooth" });
};
};