I'm trying to add full-page scrolling to the website I'm working on (using React and sadly can't get fullpage.js nor react-fullpage nor any other libs to work with my project).
Basically what I'm trying to do is disabling "normal" scrolling (I use preventDefault() on all scroll keys) and handling scrolling on my own.
Here's an example code:
window.addEventListener("wheel", e => {
const delta=e.detail? e.detail*(-120) : e.wheelDelta;
// console.log(delta);
let direction;
if ( delta !== null ) {
direction = delta > 0 ? 'up' : 'down';
}
//console.log(direction);
if(direction === "down"){
document.querySelector('.who').scrollIntoView({ alignToTop: true, behavior: 'smooth'});
}
else if (direction === "up"){
document.querySelector('.why').scrollIntoView({ alignToTop: true, behavior: 'smooth'});
}
});
This code works, however scrollIntoView (it's new functionality and requires polyfill, ik) method is fired only after user has stopped scrolling.
I've recorded my screen to better explain the issue: https://gifyu.com/image/x6Yx (be patient please, stuff starts happening after 2-3s)
As u can see here console starts logging delta and direction immediately after I scroll down, however .scrollIntoView is fired only after mouse scroll wheel stops moving - that's when the site starts scrolling.
Which means that If I just kept moving the mouse wheel down forever scrollIntoView() would never run.
I want scrolling to happen instantly after the user moves scroll wheel up or down. Does anyone has any idea on how to make that happen?