Skip to main content

Bug Tracker

Side navigation

#11606 closed enhancement (invalid)

Opened April 19, 2012 12:20PM UTC

Closed April 23, 2012 04:32PM UTC

Last modified May 13, 2013 07:52AM UTC

position() counts element margin while offset() doesn't

Reported by: subzey@gmail.com Owned by:
Priority: low Milestone: None
Component: offset Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:
Description

position().left returns position of margin-box for float'ing elements and offset().left returns position of border-box for these.

Please, see http://jsfiddle.net/subzey/ANZ7e/ for demo

I don't know if it's really a bug, but it's counter-intuitive for sure.

Attachments (0)
Change History (3)

Changed April 23, 2012 04:32PM UTC by rwaldron comment:1

component: unfiledoffset
priority: undecidedlow
resolution: → invalid
status: newclosed

http://api.jquery.com/position/

...relative to the offset parent.

http://api.jquery.com/offset/

...relative to the document.

They are not interchangeable, if you have references that show they should be, please post them here and we will re-open the ticket for review.

Changed February 20, 2013 06:42PM UTC by dmelillo@automon.com comment:2

I'm not sure why this ticket was closed as invalid. I do believe this is a bug or at least an oversight. For a more succinct example, see: http://jsfiddle.net/g4z3W/

I don't think anyone is suggesting these two functions are interchangeable, but in this particular case they should produce the same result. The offset parent of #box is the document itself, so according to the documentation one might infer that the resulting coordinates should be the same. Since position() includes the margin in the target element's point of origin and offset() does not, they will not produce the same result. This is inconsistent and misleading, and there is no hint anywhere in the documentation that indicates this subtle difference. The point of origin on the target element for position() and offset() should be the same, imo. I think this ticket deserves another peek.

Changed May 13, 2013 07:52AM UTC by jae@jae.hk comment:3

I do agree this is a slight oversight, it should be corrected. Took me like an hour to figure out offset() doesn't count margin when floated.