Skip to main content

Bug Tracker

Side navigation

#8022 closed bug (invalid)

Opened January 20, 2011 12:19PM UTC

Closed February 18, 2011 02:24PM UTC

Last modified March 14, 2012 08:08PM UTC

.offset() and .css("top")/.css("left") do not work properly when element is hidden

Reported by: Senator Owned by: Senator
Priority: low Milestone: 1.next
Component: css Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:
Description

If an element is hidden ("display" property has the "none" value), I cannot get its position as both .offset() and .css() methods return 0.

Interestingly, both methods do not work in Firefox (3.6.13 in my case) and IE (9.0.7930) but they do work correctly in Chrome (10.0.634.0) and Opera (11.00). It seems therefore that the problem is browser-specific.

Attachments (0)
Change History (12)

Changed January 20, 2011 12:28PM UTC by jitter comment:1

component: unfiledcss
owner: → Senator
priority: undecidedlow
status: newpending

Thanks for taking the time to contribute to the jQuery project by writing a bug report.

Please submit a reduced test case, which reproduces the issue you are experiencing, on http://jsfiddle.net. So that we can investigate this issue further.


How to report bugs

Changed January 21, 2011 06:03AM UTC by Senator comment:2

status: pendingnew

As you requested, I created a simple test case on the jsFiddle website. You can reproduce the the issue by following this link.

Changed January 22, 2011 08:12AM UTC by addyosmani comment:3

status: newopen

I've tested this in Chrome, IE9 and Firefox 3.6.13. At the moment Firefox is the only one I've found where the expected values aren't obtained.

Changed January 22, 2011 08:51AM UTC by Senator comment:4

The methods do work correctly in IE9. Sorry for misleading you. They also work correctly in Firefox 4 (beta 7), so the only browser where they return unexpected values is Firefox 3.

Changed January 22, 2011 09:13AM UTC by Senator comment:5

I've updated the test case so that it now allows to test the .offset() method along with the .css() method.

Changed January 24, 2011 01:16AM UTC by red+bugs@vynce.org comment:6

potentially related: in Firefox, .offset() does not account for -moz-transform: translate(x,y) changes, whereas chrome & Safari both account for -webkit-transform: translate().

Changed January 24, 2011 01:26AM UTC by red+bugs@vynce.org comment:7

Replying to [comment:6 red+bugs@…]:

potentially related: in Firefox, .offset() does not account for -moz-transform: translate(x,y) changes, whereas chrome & Safari both account for -webkit-transform: translate().

see http://jsfiddle.net/uhLpW/

Changed February 07, 2011 10:33PM UTC by websites.comunicacao@gmail.com comment:8

Replying to [ticket:8022 Senator]:

If an element is hidden ("display" property has the "none" value), I cannot get its position as both .offset() and .css() methods return 0. Interestingly, both methods do not work in Firefox (3.6.13 in my case) and IE (9.0.7930) but they do work correctly in Chrome (10.0.634.0) and Opera (11.00). It seems therefore that the problem is browser-specific.

estou com o mesmo problema, no firefox

Changed February 09, 2011 09:56PM UTC by timmywil comment:9

Just encountered this problem on one of my own sites. Swapped display: none to visibility to get correct values. I will probably do a pull request, but for now, here is a fiddle. http://jsfiddle.net/timmywil/KNGDH/3/

Changed February 14, 2011 07:29PM UTC by spongman comment:10

I was just going to file this. Here's my test case: http://jsfiddle.net/LcX7C/1/

Changed February 18, 2011 01:40PM UTC by scottgonzalez comment:11

This isn't a bug, this is documented functionality. Importantly, this isn't something jQuery can properly account for. From the offset docs:

Note: jQuery does not support getting the offset coordinates of hidden elements or accounting for borders, margins, or padding set on the body element.

Changed February 18, 2011 02:24PM UTC by jitter comment:12

resolution: → invalid
status: openclosed

As noted by scott.gonzalez this isn't a bug but specified behavior.