Bug Tracker

Modify

Ticket #11496 (closed bug: notabug)

Opened 14 months ago

Last modified 5 months ago

.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:
Blocking: Blocked by:

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

comment:1 Changed 14 months ago by anonymous

damn. not formatted correctly :(

comment:2 Changed 14 months ago by sindresorhus

  • Owner set to schinken@…
  • Status changed from new to 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 14 months ago by schinken@…

  • Status changed from pending to 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 14 months ago by sindresorhus

  • Status changed from new to pending

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

comment:5 Changed 14 months ago by schinken@…

  • Status changed from pending to new

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 14 months ago by sindresorhus

  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to dimensions

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 14 months ago by mikesherov

  • Component changed from dimensions to offset

comment:8 Changed 11 months ago by mikesherov

  • Summary changed from setting .offset() weird behaviour if display: none to .offset() called on a hidden element is positioned relative to it's old position instead of document.

comment:9 Changed 5 months ago by dmethvin

  • Status changed from open to closed
  • Resolution set to notabug

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/

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.