您好,欢迎访问一九零五行业门户网

Code:findPosX 和 findPosY_基础知识

/**
 * 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;
}
其它类似信息

推荐信息