//跨浏览器获取视口大小
function getInner(){
if(typeof window.innerWidth!=‘undefined‘){
return{
width:window.innerWidth,
height:window.innerHeight
}
}else{
return{
width:document.documentElement.clientWidth,
height:document.documentElement.clientHeight
}
}
}
//跨浏览器获取style
function getStyle(element,attr){
if(typeof window.getComputedStyle!="undefined"){ //w3c
return window.getComputedStyle(element,null)[attr];
}else if(typeof element.currentStyle!=‘undefined‘){
return element.currentStyle[attr];
}
}
//获取event对象
function getEvent(event){
retur event||window.event
}
//阻止默认行为
function preDef(event){
var e=getEvent(event);
if(typeof e.preventDefault!=‘undefined‘){//w3c
e.preventDefault();
}else{
e.returnValue=false; //ie
}
}
//跨浏览器事件绑定
function addEvent(obj,type,fn){
if(typeof obj.addEventListener!="undefined"){
obj.addEventListener(type,fn,false)
}else if(typeof obj.attachEvent!=‘undefined‘){
obj.attachEvent(‘on‘+type,function(){
fn.call(obj)
});
}
}
//跨浏览器删除事件
function removeEvent(obj,type,fn){
if(typeof obj.removeEventListener!=‘undefined‘){
obj.removeEventListener(type,fn,false)
}else if(typeof obj.detachEvent!=‘undefined‘){
obj.detachEvent(‘on‘+type,fn)
}
}