简体   繁体   中英

Event for scroll [up + down] and [left + right] separately?

I want to to make it so when the user scrolls up / down it goes left / right.

I am using this jquery mousewheel plugin (i'm open to others that achieve the same).

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

The preventDefault() is triggering for both up / down and left / right. It turns out that the functionality for up / down works great but this code makes the left / right horrible its scrolling very choppy. I would like to only preventDefault() for up / down.

Scroll Page Horizontally With Mouse Wheel

Add Deps:

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'></script>
<script type='text/javascript' src='/js/jquery.mousewheel.min.js'></script>

Add this script:

$(function() {

   $("body").mousewheel(function(event, delta) {

      this.scrollLeft -= (delta * 30);

      event.preventDefault();

   });

});

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM