1. Distance from scroll bar to top (scroll height)

var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
Copy the code

2. Distance between the scroll bar and the left end

var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
Copy the code

3. The following is the byClassName of Internet Explorer 9

The function byClassName (obj, className) {/ / determine whether support byClassName if (obj. GetElementsByClassName) {/ / support the return obj.getElementsByClassName(className); }else{var eles = obj.getElementsByTagName('*'); Var arr = []; For (var I = 0,len = eles.length; i < len; If (eles[I].className === className){arr.push(eles[I]); }} return arr; // return}}Copy the code

4. Get non-inline style compatibility

function getStyle(obj,attr){
    return window.getComputedStyle ? 
            getComputedStyle(obj,true)[attr] : obj.currentStyle[attr];
}
Copy the code

5. Obtain the compatibility of the event object

evt = evt || window.event
Copy the code

6. Obtain compatibility of mouse code values

function getButton(evt){ var e = evt || window.event; if(evt){ return e.button; }else if(window.event){ switch(e.button){case 1 : return 0; case 4 : return 1; case 2 : return 2; }}}Copy the code

7. Obtain compatibility of keyboard key coding values

var key = evt.keyCode || evt.charCode || evt.which;
Copy the code

Compatibility to prevent event bubbling

e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
Copy the code

9. Prevent compatibility with default behavior of hyperlinks

evt.preventDefault ? evt.preventDefault() : evt.returnValue = false;
Copy the code

10. Add event listener compatibility

function addEventListener(obj,event,fn,boo){ if(obj.addEventListener){ obj.addEventListener(event,fn,boo); }else if(obj.attachEvent){ obj.attachEvent('on' + event,fn); }}Copy the code

11. Remove event listener compatibility

function removeEventListener(obj,event,fn,boo){ if(obj.removeEventListener){ obj.removeEventListener(event,fn,boo); }else if(obj.detachEvent){ obj.detachEvent('on' + event,fn); }}Copy the code

12. Obtain the compatibility of event sources

var target = event.target || event.srcElement;
Copy the code