Event Object Library

Source: Internet
Author: User

1 //event object Library;2 varEventutil={3Addevent:function(OBJ,TYPE,FN) {4         if(obj.addeventlistener) {5Obj.addeventlistener (TYPE,FN,false);6}Else if(obj.attachevent) {7Obj.attachevent (' on ' +TYPE,FN);8         }9     },TenRemoveevent:function(OBJ,TYPE,FN) { One         if(obj.removeeventlistener) { AObj.removeevent (TYPE,FN,false); -}Else if(obj.detachevent) { -Obj.detachevent (' on ' +TYPE,FN); the         } -     }, -GetEvent:function(e) {//Get Event Object -         returne.target| |event.srcelement; +     }, -Preventdefault:function(e) {//block default behavior; +         if(e.preventdefault) { A E.preventdefault (); at}Else{ -E.returnvalue=false; -         } -     }, -Stoppropagation:function(e) {//stop bubbling; -         if(e.stoppropagation) { in e.stoppropagation (); -}Else{ toe.cancelbubble=true; +         } -     }, theCLIENTXY:function(e) {//gets the mouse position within the visible range; *         vart=document.documentelement.scrolltop| |Document.body.scrollTop; $         varl=document.documentelement.scrollleft| |Document.body.scrollLeft;Panax Notoginseng         return{X:l+clientx, y:t+E.clienty}; -     }, theGetrelatedtarget:function(e) { +         if(e.relatedtarget) { A             returnE.relatedtarget; the}Else if(event.toelement) { +             returne.toelement; -}Else if(e.toelement) { $             returne.fromelement; $}Else{ -             return NULL; -         } the     }, -Getbutton:function(e) {Wuyi         if(Document.implementation.hasFeature ("Mouseevents", "2.0")){ the             returnE.button; -}Else{ Wu             Switch(E.button) { -                  Case0: About                  Case1: $                  Case3: -                  Case5: -                  Case7: -                     return0; A                  Case2: +                  Case6: the                     return2; -                  Case4: $                     return1; the             } the         } the     }, theGetcharcode:function(e) { -         if(typeofevent.charcode== ' number '){ in             returnE.charcode; the}Else{ the             returnE.keycode; About         } the     }, theGetwheeldelta:function(e) { the         if(E.wheeldelta) { +             return(Client.engine.opera && client.engine.opera<9.5?-Event.wheelDelta:event.wheelDelta); -}Else{ the             return-event.detail *40;Bayi         } the     } the};

Event Object Library

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.