Scroll horizontally with mouse wheel JavaScript code example
Example: js scroll page horizontally with mouse wheel
(function() {
function scrollHorizontally(e) {
e = window.event || e;
var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
document.getElementById('yourDiv').scrollLeft -= (delta * 40);
e.preventDefault();
}
if (document.getElementById('yourDiv').addEventListener) {
document.getElementById('yourDiv').addEventListener('mousewheel', scrollHorizontally, false);
document.getElementById('yourDiv').addEventListener('DOMMouseScroll', scrollHorizontally, false);
} else {
document.getElementById('yourDiv').attachEvent('onmousewheel', scrollHorizontally);
}
})();