Jquery added the mouse intermediate function mousewheel instance code _ jquery

Source: Internet
Author: User
This article introduces the example code of adding the mouse intermediate function mousewheel in Jquery. For more information, see The Code is as follows:


(Function ($ ){
Var types = ['dommousescroll ', 'mousewheel'];
$. Event. special. mousewheel = {
Setup: function (){
If (this. addEventListener ){
For (var I = types. length; I ;){
This. addEventListener (types [-- I], handler, false );
}
} Else {
This. onmousewheel = handler;
}
},
Teardown: function (){
If (this. removeEventListener ){
For (var I = types. length; I ;){
This. removeEventListener (types [-- I], handler, false );
}
} Else {
This. onmousewheel = null;
}
}
};
$. Fn. extend ({
Mousewheel: function (fn ){
Return fn? This. bind ("mousewheel", fn): this. trigger ("mousewheel ");
},
Unmousewheel: function (fn ){
Return this. unbind ("mousewheel", fn );
}
});

Function handler (event ){
Var orgEvent = event | window. event, args = []. slice. call (arguments, 1), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
Event = $. event. fix (orgEvent );
Event. type = "mousewheel ";
// Old school scrollwheel delta
If (event. originalEvent. wheelDelta) {delta = event. originalEvent. wheelDelta/120 ;}
If (event. originalEvent. detail) {delta =-event. originalEvent. detail/3 ;}
// New school multidimen1_scroll (touchpads) deltas
DeltaY = delta;
// Gecko
If (orgEvent. axis! = Undefined & orgEvent. axis === orgEvent. HORIZONTAL_AXIS ){
DeltaY = 0;
DeltaX =-1 * delta;
}
// Webkit
If (orgEvent. wheelDeltaY! = Undefined) {deltaY = orgEvent. wheelDeltaY/120 ;}
If (orgEvent. wheelDeltaX! = Undefined) {deltaX =-1 * orgEvent. wheelDeltaX/120 ;}
// Add event and delta to the front of the arguments
Args. unshift (event, delta, deltaX, deltaY );
Return $. event. handle. apply (this, args );
}
}) (JQuery );

Call:
$ (Document). mousewheel (function (e, detail ){

}

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.