Waleed Eissa
Waleed Eissa

Reputation: 10513

Get element position relative to page bottom

I use this function to get the y-coordinate of an element relative to the page:

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'.

How can I do this?

Many thanks

Upvotes: 1

Views: 2069

Answers (1)

Sampson
Sampson

Reputation: 268344

Compare it to the height of the body/document itself.

Upvotes: 1

Related Questions