Bug Tracker

Opened 8 years ago

Closed 7 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: schinken@… Owned by: schinken@…
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 8 years ago by anonymous

damn. not formatted correctly :(

comment:2 Changed 8 years ago by sindresorhus

Owner: set to schinken@…
Status: newpending

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 8 years ago by schinken@…

Status: pendingnew

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 8 years ago by sindresorhus

Status: newpending

We're still going to need a jsfiddle to confirm and test ourselves.

comment:5 Changed 8 years ago by schinken@…

Status: pendingnew

Oh sorry,

here it is:

http://jsfiddle.net/eyEaG/

and as the counter-part, with display: block, it works:

http://jsfiddle.net/dDenH/1/

comment:6 Changed 8 years ago by sindresorhus

Component: unfileddimensions
Priority: undecidedlow
Status: newopen

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 8 years ago by mikesherov

Component: dimensionsoffset

comment:8 Changed 7 years ago by mikesherov

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 7 years ago by dmethvin

Resolution: notabug
Status: openclosed

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/

Note: See TracTickets for help on using tickets.