当前位置:Gxlcms > JavaScript > Code:findPosX和findPosY_基础知识

Code:findPosX和findPosY_基础知识

时间:2021-07-01 10:21:17 帮助过:27人阅读

/**
* Find the X position of an object, relative to the viewport
* Code copied from quirksmode.org
* @param obj Object to find x position for
*/
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;
}

/**
* Find the Y position of an object, relative to the viewport
* Code copied from quirksmode.org
* @param obj Object to find y position for
*/
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;
}

人气教程排行