while(e = e.offsetParent)
{}====CSDN====
人生起起伏伏凑字凑

解决方案 »

  1.   

    function getLeft(e)
    {
      _left = 0
      while(e = e.offsetParent)
      {
        _left += e.offsetLeft
      }
      return _left
    }====CSDN====
    人生起起伏伏凑字凑
      

  2.   

    function getLeft(e)
    {
      _left = e.offsetLeft
      while(e = e.offsetParent)
      {
        _left += e.offsetLeft
      }
      return _left
    }====CSDN====
    人生起起伏伏凑字凑
      

  3.   


    //得到控件的绝对位置
    function getctrlPosition(obj,pos){
       var t=eval("obj."+pos);
       
       while(obj=obj.offsetParent){
          t+=eval("obj."+pos);
       }
       return t;
    }
      

  4.   

    //得到控件的绝对位置
    function getctrlPosition(obj,pos)参数说明:
    obj:对象,目标控件
    pos:字符串,"offsetLeft" 或 "offsetTop"
      

  5.   

    //Rect对象
    function Rect(){
    this.width=0;
    this.height=0;
    this.left=0;
    this.top=0;
    this.right=0;
    this.bottom=0;
    }
    Rect.prototype.Cal=function () {
    this.right=this.left+this.width;
    this.bottom=this.top+this.height;
    }
    Rect.prototype.ContaintPoint=function (x,y){
    if(x>=this.left && x<=this.right && y>=this.top && y<=this.bottom) return true;
    return false;
    }
    Rect.prototype.BeCoverBy=function (rectSrc){
    return rectSrc.ContaintPoint(this.left,this.top) ||
    rectSrc.ContaintPoint(this.left,this.bottom) ||
    rectSrc.ContaintPoint(this.right,this.top) ||
    rectSrc.ContaintPoint(this.right,this.bottom) ||
    this.ContaintPoint(rectSrc.left,rectSrc.top) ||
    this.ContaintPoint(rectSrc.right,rectSrc.top) ||
    this.ContaintPoint(rectSrc.left,rectSrc.bottom) ||
    this.ContaintPoint(rectSrc.right,rectSrc.bottom);
    }
    //获取一个HTML对象的RECT属性
    function getElementRect(obj){
    var e=obj;
    var pos=new Rect;
    pos.width=obj.offsetWidth;
    pos.height=obj.offsetHeight;
    pos.left=obj.offsetLeft;
    pos.top=obj.offsetTop;
    while(e=e.offsetParent){
    pos.left+=e.offsetLeft;
    pos.top+=e.offsetTop;
    }
    pos.Cal();
    return pos;
    }