user53794
user53794

Reputation: 3830

Firefox: Get actual screen location of viewport

For firefox is there anyway to determine the TopLeft location of the "viewport" (ie the client area)? I know the height/width is available via window.innerHeight and window.innerWidth. But I also need to know "innerTop" and "innerLeft" (which don't exist).

Thanks,

Rob

Upvotes: 1

Views: 2118

Answers (4)

Neil Stockbridge
Neil Stockbridge

Reputation: 604

This seems to give the offset from the top of the document to the viewport too:

window.pageYOffset

Upvotes: -2

BYK
BYK

Reputation: 1374

Try this:

document.documentElement.getBoundingClientRect()

The result of this function will have a left and a top property which will give you what you need.

Note: This function is implemented in Fx3 so you'll need the DOM-traversing offsetParent iteration for older versions.

Upvotes: 0

Shalom Craimer
Shalom Craimer

Reputation: 21459

  • window.innerHeight - The height of the document area.
  • window.outerHeight - The height of the entire window.

You could subtract one from another, and get the distance of the document area from the top of the window, plus the height of the status bar.

Upvotes: 2

bobince
bobince

Reputation: 536567

If you can get a mouse event, you can look at its event.screenX/screenY properties and subtract the event.clientX/clientY properties. This is even cross-browser compatible (DOM Level 2 Events).

Upvotes: 2

Related Questions