|
1 | 1 | # jQuery Mouse Wheel Plugin
|
2 | 2 |
|
3 |
| -A [jQuery](http://jquery.com/) plugin that adds cross-browser mouse wheel support. |
| 3 | +A [jQuery](http://jquery.com/) plugin that adds cross-browser mouse wheel support with delta normalization. |
4 | 4 |
|
5 | 5 | In order to use the plugin, simply bind the `mousewheel` event to an element.
|
| 6 | + |
6 | 7 | It also provides two helper methods called `mousewheel` and `unmousewheel`
|
7 |
| -that act just like other event helper methods in jQuery. The event callback |
8 |
| -receives three extra arguments which are the normalized "deltas" of the mouse wheel. |
| 8 | +that act just like other event helper methods in jQuery. |
| 9 | + |
| 10 | +The event object is updated with the normalized `deltaX` and `deltaY` properties. |
| 11 | +In addition there is a new property on the event object called `deltaFactor`. Multiply |
| 12 | +the `deltaFactor` by `deltaX` or `deltaY` to get the scroll distance that the browser |
| 13 | +has reported. |
9 | 14 |
|
10 | 15 | Here is an example of using both the bind and helper method syntax:
|
11 | 16 |
|
12 | 17 | ```js
|
13 |
| -// using bind |
14 |
| -$('#my_elem').on('mousewheel', function(event, delta, deltaX, deltaY) { |
15 |
| - console.log(delta, deltaX, deltaY); |
| 18 | +// using on |
| 19 | +$('#my_elem').on('mousewheel', function(event) { |
| 20 | + console.log(event.deltaX, event.deltaY, event.deltaFactor); |
16 | 21 | });
|
17 | 22 |
|
18 | 23 | // using the event helper
|
19 |
| -$('#my_elem').mousewheel(function(event, delta, deltaX, deltaY) { |
20 |
| - console.log(delta, deltaX, deltaY); |
| 24 | +$('#my_elem').mousewheel(function(event) { |
| 25 | + console.log(event.deltaX, event.deltaY, event.deltaFactor); |
21 | 26 | });
|
22 | 27 | ```
|
23 | 28 |
|
| 29 | +The old behavior of adding three arguments (`delta`, `deltaX`, and `deltaY`) to the |
| 30 | +event handler is now deprecated and will be removed in later releases. |
| 31 | + |
| 32 | + |
24 | 33 | ## See it in action
|
25 | 34 | [See the tests on Github](http://brandonaaron.github.io/jquery-mousewheel/test).
|
26 | 35 |
|
|
0 commit comments