ded / bonzo

library agnostic, extensible DOM utility
Other
1.32k stars 137 forks source link

Object offset() does not take margin into consideration. #120

Open magebarf opened 11 years ago

magebarf commented 11 years ago

The offset function does not include explicitly set margins in its calculations if parents are relatively positioned. This makes the values returned not quite match the expected values for elements using it.

The odd part seems to be that auto margins seems to be calculated correctly (when running through chrome at least).

I've made a clear and stripped down example of this available at: http://sargy.net/testcase/bonzo/offset.html

(jsFiddle tucks the html inside their layout, so the offset values there is not as easy to know if they are wrong)

magebarf commented 11 years ago

Same behavior verified with latest stable versions on Windows 8 (above mentioned chrome being run on OS X):

ryanve commented 11 years ago

The issue seems isolated to when the body is position:relative. If the body is in its natural position:static then descendent offsets seem correct even when relative. Do your findings agree?

magebarf commented 11 years ago

Yes, indeed you are right.

The drawbacks of being in a too simple sandbox for testing to start off with. :)

If body has relative position then elements place as direct child will not include the margin. If a element has no parent nodes other than the body element which has a position attribute (and the body has relative position set), the same case applies it seems, I whipped together a small example similar to my first one:

http://sargy.net/testcase/bonzo/offset2.html (and sorry for hurting your eyes with my attempts to make things as clear as possible) :)