JS Roller Event compatible notation

Source: Internet
Author: User

/** * Simple Event Add method */define (function (Require, exports, module) {exports.addevent = (function (window, undefined) {            var _eventcompat = function (event) {var type = Event.type;  if (type = = ' Dommousescroll ' | | type = = ' MouseWheel ') {Event.delta = (Event.wheeldelta)? Event.wheeldelta            /:-(Event.detail | | 0)/3;            }//alert (Event.delta);                if (event.srcelement &&!event.target) {event.target = event.srcelement;  } if (!event.preventdefault && event.returnvalue!== undefined) {Event.preventdefault =                function () {event.returnvalue = false;            }; }            /*                ......        Some other compatibility processing */return event;        }; if (window.addeventlistener) {return function (el, type, FN, capture) {if (type = = =) MouseWheel "&& Document.mozfullscreen!== undefined) {type = "dommousescroll";                } el.addeventlistener (Type, function (event) {Fn.call (this, _eventcompat (event)); }, Capture | |            FALSE); }} else if (window.attachevent) {return function (el, type, FN, capture) {El.attacheven                    T ("on" + Type, function (event) {event = Event | | | window.event;                    Fn.call (EL, _eventcompat (event));            });        }} return function () {};        }) (window); });

So, we can use mousewheel the event very calmly. For example:

Addevent (DOM, "MouseWheel", function (event) {    if (Event.delta < 0) {alert ("Mouse rolled up!") "); }});

  

JS Roller Event compatible notation

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.