Opened 11 years ago
Closed 10 years ago
#11496 closed bug (notabug)
.offset() called on a hidden element is positioned relative to it's old position instead of document.
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | offset | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
var $thumbThingy = $('<div id="basket-thumbview"></div>').appendTo( $('body') );
$thumbThingy.css('display', 'none' );
setInterval( function() {
$thumbThingy.offset( { left: 10, top: 10 } ); console.log( $thumbThingy.css('left'), $thumbThingy.css('top') );
}, 1000 );
Results in:
10px -362px 15820px -724px 15830px -1086px 15840px -1448px 15850px -1810px 15860px -2172px 15870px -2534px 15880px -2896px 15890px -3258px 158100px -3620px 158110px -3982px
Change History (9)
comment:1 Changed 11 years ago by
comment:2 Changed 11 years ago by
Owner: | set to [email protected]… |
---|---|
Status: | new → pending |
Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.
Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.
comment:3 Changed 11 years ago by
Status: | pending → new |
---|
the bug seems to happen if display is none.
The line "curOffset = curElem.offset()" in jQuery.offset.setOffset returns everytime top,left = 0
So this calculation:
( options.top - curOffset.top ) + curTop;
is like:
( 10 - 0 ) + 10
And result in a growing value
Traced it down to getOffset, but not sure what this causes the problem inside that function
comment:4 Changed 11 years ago by
Status: | new → pending |
---|
We're still going to need a jsfiddle to confirm and test ourselves.
comment:5 Changed 11 years ago by
Status: | pending → new |
---|
Oh sorry,
here it is:
and as the counter-part, with display: block, it works:
comment:6 Changed 11 years ago by
Component: | unfiled → dimensions |
---|---|
Priority: | undecided → low |
Status: | new → open |
A better description of this issue would be:
If .offset() is called on a hidden element, it will be positioned relative to it's old position instead of the document.
Improved testcase: http://jsfiddle.net/mofle/KYdt7/
comment:7 Changed 11 years ago by
Component: | dimensions → offset |
---|
comment:8 Changed 11 years ago by
Summary: | setting .offset() weird behaviour if display: none → .offset() called on a hidden element is positioned relative to it's old position instead of document. |
---|
comment:9 Changed 10 years ago by
Resolution: | → notabug |
---|---|
Status: | open → closed |
Note: jQuery does not support getting the offset coordinates of hidden elements or accounting for borders, margins, or padding set on the body element. -- http://api.jquery.com/offset/
damn. not formatted correctly :(