How can I change the pace of scroll using javascript?

I figured out how to make it so when i scroll once, it goes right to the second page, but its ways too fast, so i reset it to its original js:

document.documentElement.scrollLeft -= (delta * 40); // Multiplied by 40 made it 1866 
      document.body.scrollLeft -= (delta * 40); // Multiplied by 40
      e.preventDefault();
    }

I really like the speed,pace, smoothness of nemesis, how can I make it like that? would I need to use some library? thank you!

CODEPEN

Hi @niadaniels40, you might use window.scrollBy() where you can just set the behavior to “smooth”:

var delta = (-e.wheelDelta || e.detail) * 40
window.scrollBy({ left: delta, behavior: 'smooth' })

For more control over the smoothness you might indeed consider a library though, or check out common easing functions (here’s a cheat sheet, for instance) if you want to implement it yourself.

1 Like