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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
WordPress大学
WordPress大学
小众软件
小众软件
爱范儿
爱范儿
美团技术团队
宝玉的分享
宝玉的分享
N
Netflix TechBlog - Medium
G
Google Developers Blog
Vercel News
Vercel News
J
Java Code Geeks
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
博客园 - 【当耐特】
Stack Overflow Blog
Stack Overflow Blog
有赞技术团队
有赞技术团队
月光博客
月光博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
L
LangChain Blog
Engineering at Meta
Engineering at Meta
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC

博客园 - .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"
    }
}