#11606 closed enhancement (invalid)
position() counts element margin while offset() doesn't
Reported by: | 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 11 years ago by
Component: | unfiled → offset |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | new → closed |
comment:2 Changed 10 years ago by
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 10 years ago by
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.
http://api.jquery.com/position/
http://api.jquery.com/offset/
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.