简体   繁体   English

获取元素相对于页面底部的位置

[英]Get element position relative to page bottom

I use this function to get the y-coordinate of an element relative to the page: 我使用此函数来获取元素相对于页面的y坐标:

function getY(oElement)
{
  var curtop = 0;
  if (oElement.offsetParent) 
  {
    while (oElement.offsetParent) 
    {
      curtop += oElement.offsetTop;
      oElement = oElement.offsetParent;
    }
  }
  else if (oElement.y)
  {
    curtop += oElement.y;
  }

  return curtop;
}

Now I want to do the same thing but get the position relative to the bottom instead of the top, there doesn't seem to be something like 'offsetBottom'. 现在,我想做同样的事情,但是要获得相对于底部而不是顶部的位置,似乎不存在“ offsetBottom”之类的东西。

How can I do this? 我怎样才能做到这一点?

Many thanks 非常感谢

将其与正文/文档本身的高度进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM