Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active June 16, 2022 16:28
Show Gist options
  • Save vielhuber/6a894f6fa083949f6a3b4ea4c8a350fe to your computer and use it in GitHub Desktop.
Save vielhuber/6a894f6fa083949f6a3b4ea4c8a350fe to your computer and use it in GitHub Desktop.
on mousewheel vanilla js scroll horizontally #js
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();
});
@vielhuber
Copy link
Author

@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