showing results for - "js scroll page horizontally with mouse wheel"
Lennart
31 Jun 2020
1(function() {
2    function scrollHorizontally(e) {
3        e = window.event || e;
4        var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
5        document.getElementById('yourDiv').scrollLeft -= (delta * 40); // Multiplied by 40
6        e.preventDefault();
7    }
8    if (document.getElementById('yourDiv').addEventListener) {
9        // IE9, Chrome, Safari, Opera
10        document.getElementById('yourDiv').addEventListener('mousewheel', scrollHorizontally, false);
11        // Firefox
12        document.getElementById('yourDiv').addEventListener('DOMMouseScroll', scrollHorizontally, false);
13    } else {
14        // IE 6/7/8
15        document.getElementById('yourDiv').attachEvent('onmousewheel', scrollHorizontally);
16    }
17})();
18