5

related to browser window's upper left corner of client area.

lovespring
  • 19,051
  • 42
  • 103
  • 153

1 Answers1

4

Try this: http://www.quirksmode.org/js/findpos.html

Ariel Popovsky
  • 4,787
  • 2
  • 28
  • 30
  • 1
    That's the right idea, but I believe there are some browser inconsistencies in the way `element.offsetParent` and `element.offsetTop`/`element.offsetLeft` is handled. I'd research how the major frameworks the doing this before copy/pasting that code... – Øystein Riiser Gundersen Sep 07 '09 at 14:41
  • 1
    Actually quirksmode has been dealing with cross browser compatibility for years but if you can use Jquery (or part of it) take a look at the offset method http://docs.jquery.com/CSS/offset – Ariel Popovsky Sep 07 '09 at 15:25
  • 2
    Indeed. The jQuery implementation is pretty hairy: http://code.google.com/p/jqueryjs/source/browse/trunk/jquery/src/offset.js Prototype's `Element.viewportOffset()` may be worth looking at as well http://prototypejs.org/assets/2009/8/31/prototype.js – Øystein Riiser Gundersen Sep 07 '09 at 18:41