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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@woodydaniel the idea is to entirely skip that function and not to call e.preventDefault when you have reached the end.