Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#11606 closed enhancement (invalid)

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

Reported by: subzey@… 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.

Change History (3)

comment:1 Changed 7 years ago by Rick Waldron

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.

comment:2 Changed 6 years ago by dmelillo@…

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.

comment:3 Changed 6 years ago by jae@…

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.

Note: See TracTickets for help on using tickets.