Skip to content

Instantly share code, notes, and snippets.

@edkf
Created February 14, 2018 02:28
Show Gist options
  • Save edkf/cbea091764b0bb2100e88bd31142ea3e to your computer and use it in GitHub Desktop.
Save edkf/cbea091764b0bb2100e88bd31142ea3e to your computer and use it in GitHub Desktop.
const el = document.querySelector('#scroller');
function scrollHorizontally(e) {
e = window.event || e;
e.preventDefault();
el.scrollLeft -= (e.wheelDelta || -e.detail);
}
function init() {
if (!el) {
return;
}
if (el.addEventListener) {
el.addEventListener('mousewheel', scrollHorizontally, false);
el.addEventListener('DOMMouseScroll', scrollHorizontally, false);
} else {
el.attachEvent('onmousewheel', scrollHorizontally);
}
}
export default init;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment