function getLeft(root)
{
    var left = 0;
    while(root != null)
    {
        left += root.offsetLeft;
        root = root.offsetParent; 
    }      
    return left; 
}

解决方案 »

  1.   

    这个是相对于左边的,或者相对于body顶端的,如果出现滚动条向下拉伸,就是说那个体是窗口是按照当前窗口的上下距离来判断的,可能页面都到最下面了,但是他跟窗口上边距的相对坐标可能是不变的,但是对于窗体的body都有1500px了
      

  2.   

    下面几个函数,尤其是最后一个  getAvailableHeight  怎么使用的,calBrother,calParent都是bool 型的,但是不知道表示什么意思,怎么使用function findPosX(obj)
    {var curleft=0;if(obj.offsetParent){while(obj.offsetParent){curleft+=obj.offsetLeft
    obj=obj.offsetParent;}}
    else if(obj.x)
    curleft+=obj.x;return curleft;}function findPosY(obj)
    {var curtop=0;if(obj.offsetParent){while(obj.offsetParent){curtop+=obj.offsetTop
    obj=obj.offsetParent;}}
    else if(obj.y)
    curtop+=obj.y;return curtop;}
    function getDocumentWidth(){var contentWidth;if(window.innerHeight){contentWidth=window.innerWidth-6;}else if(document.documentElement.clientWidth){contentWidth=document.documentElement.clientWidth;}else{contentWidth=document.body.clientWidth;}
    return contentWidth;}function getDocumentHeight(){var contentHeight;if(window.innerHeight){contentHeight=window.innerHeight-6;}else if(document.documentElement.clientHeight){contentHeight=document.documentElement.clientHeight;}else{contentHeight=document.body.clientHeight;}
    return contentHeight;}function getAvailableHeight(obj,calBrother,calParent){if(obj.parentNode&&obj.parentNode.tagName&&obj.parentNode.tagName.toLowerCase()!='html'){var y;if(calParent){if(obj.parentNode.style&&obj.parentNode.style.height){y=obj.parentNode.style.height.toLowerCase().split('px')[0];}else{y=obj.parentNode.offsetHeight;}}else{y=getDocumentHeight()-findPosY(obj.parentNode);}if(!calBrother)return y;var brothers=obj.parentNode.childNodes;var b;for(var i=0;i<brothers.length;i++){b=brothers[i];if(b!=obj&&b.nodeType==1&&!(b.style&&b.style.display&&b.style.display=='none')&&b.tagName.toLowerCase()!='script'&&b.tagName.toLowerCase()!='style'){if(b.innerHTML!=''){y-=b.offsetHeight;}}}
    return y;}else{return null}}