获取控件的绝对位置(该控件非position:absolute)

来源:互联网 发布:vscode for mac 编辑:程序博客网 时间:2024/06/06 12:54
 
  1. function CPos(x,y)
  2.         {
  3.             this.x = x;
  4.             this.y = y;
  5.         }
  6.         function GetObjPos(ATarget)
  7.         {
  8.             var target = ATarget;
  9.             var pos = new CPos(target.offsetLeft, target.offsetTop);
  10.             var target = target.offsetParent;
  11.             while (target)
  12.             {
  13.                 pos.x += target.offsetLeft;
  14.                 pos.y += target.offsetTop;
  15.                 target = target.offsetParent
  16.             }
  17.             return pos;
  18.         }
原创粉丝点击