So after some more testing, I don't think it's possible to write a script that can in all cases get the exact position of an element. The MochiKit.DOM.elementPosition script is correct, but we should mention the caveat that the coordinates of elements with margins, borders, and paddings are unlikely to be returned correctly. Here's my summary, with test cases:
http://hartshorne.ca/2006/01/20/javascript_positioning/

This comment from Mozilla's bug tracker sums it up:

"The problem to begin with, the origin of the problem is that MSDN does not define strictly, explicitly how offsetLeft/offsetTop should be computed in normal situations and in various other situations. Even offsetParent is not defined clearly: there is no precise spec. - formal rigorous spec - identifying
how the offsetParent can be, should be determined. offsetLeft, offsetTop
definitions are circularly dependent, self-inter-dependent to offsetParent
definition.

Add to this quirks mode vs standards rendering mode, and other properties
(padding, border, margin, box-sizing) which  interfere or affect too
calculations of offsetLeft, offsetTop or which may influence too the way
offsetParent is to be defined and then you have a real mess, headache,
impossible task."

https://bugzilla.mozilla.org/show_bug.cgi?id=307502#c4

Reply via email to