Code:findPosX 和 findPosY

2018-09-21 21:27

阅读:608

  /**
*FindtheXpositionofanobject,relativetotheviewport
*@paramobjObjecttofindxpositionfor
*/
functionfindPosX(obj)
{
varcurleft=0;
if(obj.offsetParent)
{
while(obj.offsetParent)
{
curleft+=obj.offsetLeft
obj=obj.offsetParent;
}
}
elseif(obj.x)
curleft+=obj.x;
returncurleft;
}

/**
*FindtheYpositionofanobject,relativetotheviewport
*Codecopiedfromquirksmode.org
*@paramobjObjecttofindypositionfor
*/
functionfindPosY(obj)
{
varcurtop=0;
if(obj.offsetParent)
{
while(obj.offsetParent)
{
curtop+=obj.offsetTop
obj=obj.offsetParent;
}
}
elseif(obj.y)
curtop+=obj.y;
returncurtop;
}


评论


亲,登录后才可以留言!