惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
V
V2EX
博客园 - 【当耐特】
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
量子位
MyScale Blog
MyScale Blog
Hugging Face - Blog
Hugging Face - Blog
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
月光博客
月光博客
I
InfoQ
WordPress大学
WordPress大学
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
小众软件
小众软件
罗磊的独立博客
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - .net小鸟

产品很重要 JQUERY FAQ 无法打开到主机的连接,在端口xxx连接失败 eclipse的调试技术 js parseInt与排序 html到asp.net样式变乱 django学习资料 FAQ python31操作MySql jquery iframe 父子互操作 .net连接mysql maven下载地址 jquery操作ul notepad++中用正则表达式 jquery 两个控件同享一个function javascript 经常会用到的东西 javascript template javascript closure anonymous function javafirststep
js工具类
.net小鸟 · 2011-09-01 · via 博客园 - .net小鸟

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"
    }
}