js工具类
var tools = {
fixE:function(e)
{
return e||window.event;
},
getOffset:function(obj,isleft)
{
var ab=0;
while(obj!=null)
{
ab+=obj["offset"+(isleft?"Left":"Top")];
obj=obj.offsetParent;
};
return ab;
},
getDistance:function(left,top,left2,top2)
{
return Math.sqrt(Math.pow(left-left2,2)+Math.pow(top-top2,2))
},
preventDefault:function(e)
{
e=this.fixE(e);
if(e.preventDefaults)
e.preventDefaults();
else
e.returnValue=false;
},
cancelBubble:function(e)
{
e=this.fixE(e);
if(e.stopPropagation)
{
e.stopPropagation();
}
else
{
e.cancelBubble=true;
}
},
disableSelection:function(target){
if (typeof target.onselectstart!="undefined") //IE route
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
target.style.MozUserSelect="none"
else //All other route (ie: Opera)
target.onmousedown=function(){return false}
target.style.cursor = "default"
}
}
fixE:function(e)
{
return e||window.event;
},
getOffset:function(obj,isleft)
{
var ab=0;
while(obj!=null)
{
ab+=obj["offset"+(isleft?"Left":"Top")];
obj=obj.offsetParent;
};
return ab;
},
getDistance:function(left,top,left2,top2)
{
return Math.sqrt(Math.pow(left-left2,2)+Math.pow(top-top2,2))
},
preventDefault:function(e)
{
e=this.fixE(e);
if(e.preventDefaults)
e.preventDefaults();
else
e.returnValue=false;
},
cancelBubble:function(e)
{
e=this.fixE(e);
if(e.stopPropagation)
{
e.stopPropagation();
}
else
{
e.cancelBubble=true;
}
},
disableSelection:function(target){
if (typeof target.onselectstart!="undefined") //IE route
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
target.style.MozUserSelect="none"
else //All other route (ie: Opera)
target.onmousedown=function(){return false}
target.style.cursor = "default"
}
}