Created
February 14, 2018 02:28
-
-
Save edkf/cbea091764b0bb2100e88bd31142ea3e to your computer and use it in GitHub Desktop.
This file contains 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
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