Last active
June 16, 2022 16:28
-
-
Save vielhuber/6a894f6fa083949f6a3b4ea4c8a350fe to your computer and use it in GitHub Desktop.
on mousewheel vanilla js scroll horizontally #js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('wheel', function(e) | |
{ | |
if(e.type != 'wheel') | |
{ | |
return; | |
} | |
let delta = ((e.deltaY || -e.wheelDelta || e.detail) >> 10) || 1; | |
delta = delta * (-300); | |
document.documentElement.scrollLeft -= delta; | |
// safari needs also this | |
document.body.scrollLeft -= delta; | |
e.preventDefault(); | |
}); |
@themevan did you manage to implement that code?
I’m wanting the same functionality but not fully understanding the pseudo code posted.
@woodydaniel the idea is to entirely skip that function and not to call e.preventDefault when you have reached the end.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, just check the vertical scroll position and don't execute the function above if you passed the end.
Pseudo code:
You then have to also check when you again scroll up, but I leave the implementation to you. :)