Code:findPosX 和 findPosY
2018-09-21 21:27
/**
*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;
}
文章标题:Code:findPosX 和 findPosY
文章链接:http://soscw.com/index.php/essay/16705.html