Introduction to Mouse wheel events

Source: Internet
Author: User

Brief introduction

IE6 implements the mouse wheel event MouseWheel, which contains a property that the mouse event does not have, Wheeldelta, which

Attribute values are always multiples of 120, and slide up one unit, the Wheeldelta value is 120, and the downward is-120. Then Chrome,opera,

The event is also implemented by Safari. Opera10 Previous version of the Wheeldelta value of the symbolic processing error, need to be modified. But Firefox didn't

There is this event, but instead use Dommousescroll. This event is only supported by Firefox, so it can be individually compatible with Firefox.

In addition, in order to be compatible with these two events, HTML5 also provides a standard version of the wheel event, compared to the new browser basically implemented the event.

Chrome31+,firefox 17+,ie9+,safari 7.0.5 and the new version of opera using the WebKit kernel, opera using the Carakan kernel

The event is not supported. The wheel event has the DeltaX, DeltaY, and Deltaz properties, which default to 100.

In summary, the current compatibility of wheel events is not ideal, mousewheel compatibility is best, applicable to all except Firefox browser, for

Firefox is compatible with the individual.

  

1Addevent =function (type,callback,usecapture) {2     if(window.addeventlistener) {3          This. AddEventListener (Type,callback,!!usecapture);4}Else if(window.attachevent) {5          This. attachevent (' on'+type,callback);6     }7     returncallback;8 }9Wheel =function (el,callback) {Ten     varType ='MouseWheel'; One     Try{ ADocument.createevent ('mousescrollevents'); -Type ='Dommousescroll'; -}Catch(e) {} theEl.addevent =addevent; - el.addevent (Type,function (e) { -E = e | | Window.Event; -         varWheeldelta,delta; +         if('Wheeldelta' inche) { -Wheeldelta = E.wheeldelta;//Positive scroll up +             if(Window.opera && window.opera.version () <Ten){ AE.delta = parseint (-wheeldelta)/ -;//Wheeldelta under Safari is a floating-point number at             } -E.delta = parseint (Wheeldelta)/ -; -}Else if('Detail' inche) { -E.wheeldelta =-e.detail * +;//fix Firefox without Wheeldelta bug,detail for +-3 -E.delta = E.wheeldelta/ -; -         } in Callback.call (el,e); -         //Stop bubbling Up toE.stoppropagation &&e.stoppropagation (); +         if("stopbubble" inche) e.stopbubble =true; -         return false; the},false); *};

Introduction to Mouse wheel events

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.