gniewleone
gniewleone

Reputation: 445

Get horizontal scroll event in js

What I want to do, is to catch the event when the user is scrolling div horizontally. For vertical scroll I am using event 'mousewheel' and it's working properly. ( horizontal scroll is performed by a two finger drag on the touchpad - I am testing on Mac OS).

Upvotes: 19

Views: 48384

Answers (2)

Mateusz Rogulski
Mateusz Rogulski

Reputation: 7455

You can handle horizontal scrolling by :

$("#someContainer").on("scroll", function (e) {
            horizontal = e.currentTarget.scrollLeft;
            vertical = e.currentTarget.scrollTop;
            });

In this case this bind all kind of scroll events on this element so you can also handle

Vertical by e.currentTarget.scrollTop

and

Horizontal by e.currentTarget.scrollLeft

Upvotes: 29

Per Salbark
Per Salbark

Reputation: 3645

I don't have the proper setup to test this, but $.scroll() should do the trick. It's probably preferable to binding the mousewheel event as well. People use all means of scrolling ;)

Upvotes: 0

Related Questions