Used to add support for cross-browser mouse wheel.
You can use the mousewheel event in either of the following ways:
- use the mousewheel and unmousewheel event functions.
- use the classic bind and unbind functions.
$ ('div. mousewheel_example '). mousewheel (FN); $ ('div. mousewheel_example '). BIND ('mousewheel ', FN);
The processing function of the mousewheel event has a slight change. In addition to the first parameter event, it also receives the second parameter delta. The Delta parameter can be used to obtain the direction and speed of the scroll wheel. If the Delta value is negative, the scroll wheel is scroll down, and the positive is upward.
The following is an exampleSource code:
Jquery (function ($) {$ ('div. mousewheel_example '). BIND ('mousewheel', function (event, Delta) {var dir = delta> 0? 'Up': 'low', Vel = math. ABS (DELTA); $ (this ). text (DIR + 'at a velocity of '+ VEL); Return false ;});});
Download
You can download other versions from GitHub.
Use
To use this function, you only need to bind the event handler function to the 'mousewheel' event of the target element.
The mousewheel plug-in also provides two event functions: mousewheel and unmousewheel. You can call these two functions on the target element and specify the callback function in the parameter.
The first parameter of the Event Callback Function is event, and the second parameter is delta, which represents the variable value of the mouse wheel.
The following are examples of the above two methods:
// Binding method $ ('# my_elem '). BIND ('mousewheel ', function (event, Delta) {console. log (DELTA) ;}); // event Function Method $ ('# my_elem '). mousewheel (function (event, Delta) {console. log (DELTA );});