- Notifications
You must be signed in to change notification settings - Fork1.7k
A jQuery plugin that adds cross-browser mouse wheel support.
License
jquery/jquery-mousewheel
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
AjQuery plugin that adds cross-browser mouse wheel support with delta normalization.
In order to use the plugin, simply bind themousewheel
event to an element.
The event object is updated with the normalizeddeltaX
anddeltaY
properties.In addition, there is a new property on the event object calleddeltaFactor
. MultiplythedeltaFactor
bydeltaX
ordeltaY
to get the scroll distance that the browserhas reported.
Here is an example of using both the bind and helper method syntax:
$("#my_elem").on("mousewheel",function(event){console.log(event.deltaX,event.deltaY,event.deltaFactor);});
The old behavior of adding three arguments (delta
,deltaX
, anddeltaY
) to theevent handler is now deprecated and will be removed in later releases.
The combination of browsers, operating systems, and devices offer a huge range of possible delta values. In fact if the useruses a trackpad and then a physical mouse wheel the delta values can differ wildly. This plugin normalizes thosevalues so you get a whole number starting at +-1 and going up in increments of +-1 according to the force oracceleration that is used. This number has the potential to be in the thousands depending on the device.
In some use-cases we prefer to have the normalized delta but in others we want to know how far the browser shouldscroll based on the users input. This can be done by multiplying thedeltaFactor
by thedeltaX
ordeltaY
event property to find the scroll distance the browser reported.
ThedeltaFactor
property was added to the event object in 3.1.5 so that the actual reported delta value can beextracted. This is a non-standard property.
git clone git@github.com:jquery/jquery-mousewheel.gitcd jquery-mousewheel/npm installnpmtest
The unit tests arevery basic sanity checks; improvements welcome.To fully test the plugin, loadtest/index.html in each supportedbrowser and follow the instructions at the top of the file after the unit tests finish.
About
A jQuery plugin that adds cross-browser mouse wheel support.
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.