mohamad javidi
mohamad javidi

Reputation: 83

How to change the direction of mousewheel scrolling on an HTML page?

Is there a way to use Javascript or jQuery to change the direction of scrolling on an HTML page (with mouse wheel) from up to down -> left to right?

Upvotes: 7

Views: 7708

Answers (2)

Maximillian Laumeister
Maximillian Laumeister

Reputation: 20359

Here is a short function that makes your document scroll horizontally instead of vertically using the mousewheel:

$(function() {
   $("html, body").mousewheel(function(event, delta) {
      this.scrollLeft -= (delta * 30);
      event.preventDefault();
   });
});

You will need to include the jquery.mousewheel.min.js script in your page for it to work.

Working JSFiddle example: https://jsfiddle.net/1zugp6w6/1/

Source

Upvotes: 3

mohamad javidi
mohamad javidi

Reputation: 83

$(document).ready(function() {
    $('html, body, *').mousewheel(function(e, delta) {
        this.scrollLeft -= (delta * 40);
        e.preventDefault();
    });
});

that work for all browser

Upvotes: 1

Related Questions