dom scrollX scrollY innerWidth cilentWidth
function getScroll(){ return { x:window.pageXOffset?window.pageXOffset:document.body.scrollLeft+document.documentElement.scrollLeft, y:window.pageYOffset?window.pageYOffset:document.body.scrollTop+document.documentElement.scrollTop, } }
function getViewportWH(){ if(window.innerWidth){ return { w:window.innerWidth, h:window.innerHeight, } }else{ if(document.compatMode==='BackCompat'){ return { w:document.body.clientWidth, h:document.body.clientHeight, } }else{ return { w:document.documentElement.clientWidth, h:document.documentElement.clientHeight, } } } } console.log(getViewportWH())
function addEvent(ele,type,handle){ if(ele.addEventListener){ ele.addEventListener(type,handle,false) }else if(ele.attachEvent){ ele.attachEvent('on'+type,function(){ handle.call(ele) }) }else{ ele['on'+type]=handle } }
//绑定事件 function addEvent(ele,type,handle){ if(ele.addEventListener){ ele.addEventListener(type,handle,false) }else if(ele.attachEvent){ ele.attachEvent('on'+type,function(){ handle.call(ele) }) }else{ ele['on'+type]=handle } } //解除事件 function removeEvent(ele,event,handle){ if(ele.removeEventListener){ ele.removeEventListener(type,handle,false) }else if(ele.detachEvent){ ele.detachEvent('on'+type,function(){ handle.call(ele) }) }else{ ele['on'+type]='' } } //阻止冒泡 function stopPop(e){ if(e.stopPropagation){ e.stopPropagation() }else{ e.cancelBubble=true } } //阻止默认事件 //1、return false 2、event.preventDefault() 3、event.returnValue=false function stopDefaultEve(e){ if(e.preventDefault){ e.preventDefault() }else{ e.returnValue=false } }