Code:findPosX 和 findPosY

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Code:findPosX 和 findPosY

  2020-05-11 我要评论
/**
 * 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;
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们