Skip to main content

Bug Tracker

Side navigation

#11496 closed bug (notabug)

Opened March 21, 2012 12:37PM UTC

Closed January 04, 2013 08:48PM UTC

.offset() called on a hidden element is positioned relative to it's old position instead of document.

Reported by: schinken@hackerspace-bamberg.de Owned by: schinken@hackerspace-bamberg.de
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

Attachments (0)
Change History (9)

Changed March 21, 2012 12:39PM UTC by anonymous comment:1

damn. not formatted correctly :(

Changed March 21, 2012 11:51PM UTC by sindresorhus comment:2

owner: → schinken@hackerspace-bamberg.de
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.

Changed March 22, 2012 07:36AM UTC by schinken@hackerspace-bamberg.de comment:3

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

Changed March 22, 2012 09:15AM UTC by sindresorhus comment:4

status: newpending

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

Changed March 22, 2012 09:26AM UTC by schinken@hackerspace-bamberg.de comment:5

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/

Changed March 22, 2012 03:36PM UTC by sindresorhus comment:6

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/

Changed April 10, 2012 02:53AM UTC by mikesherov comment:7

component: dimensionsoffset

Changed July 06, 2012 05:01AM UTC by mikesherov comment:8

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.

Changed January 04, 2013 08:48PM UTC by dmethvin comment:9

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/