Mousewheel-responds to cross-browser mouse wheel events

Source: Internet
Author: User

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 );});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.