Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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); // Multiplied by 40
        e.preventDefault();
    }
    if (document.getElementById('yourDiv').addEventListener) {
        // IE9, Chrome, Safari, Opera
        document.getElementById('yourDiv').addEventListener('mousewheel', scrollHorizontally, false);
        // Firefox
        document.getElementById('yourDiv').addEventListener('DOMMouseScroll', scrollHorizontally, false);
    } else {
        // IE 6/7/8
        document.getElementById('yourDiv').attachEvent('onmousewheel', scrollHorizontally);
    }
})();
Comment

PREVIOUS NEXT
Code Example
Javascript :: mock single function from module jest 
Javascript :: npm express async handler 
Javascript :: javascript prepend string to array 
Javascript :: es6 compare two arrays 
Javascript :: how select start from id in jquery 
Javascript :: nested array loop in javascript 
Javascript :: get day name from date javascript 
Javascript :: import axios 
Javascript :: html form pattern message 
Javascript :: how to know type of dom element in js 
Javascript :: nuxt window is not defined 
Javascript :: express get url parameters 
Javascript :: js sort string array 
Javascript :: add an image to a div with javascript 
Javascript :: javascript how to change anchor style 
Javascript :: react confirm alert 
Javascript :: js window redirect 
Javascript :: redirect to different page in javascript 
Javascript :: html call javascript variable 
Javascript :: material ui select helper text 
Javascript :: check if input is valid 
Javascript :: regex match to first instance 
Javascript :: change event listener in javascript 
Javascript :: match any character across multiple line regex 
Javascript :: localstorage save array 
Javascript :: declaration vue 3 variables 
Javascript :: javascript remove duplicate in two arrays 
Javascript :: javascript integer length 
Javascript :: react native run android 
Javascript :: jquery remove style 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =