Code:findPosX 和 findPosY

      2020-08-01 16:51      编程语言
/**
*FindtheXpositionofanobject,relativetotheviewport
*Codecopiedfromquirksmode.org
*@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;
}