#8022 closed bug (invalid)
.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.
Change History (12)
comment:1 Changed 11 years ago by
Component: | unfiled → css |
---|---|
Owner: | set to Senator |
Priority: | undecided → low |
Status: | new → pending |
comment:2 Changed 11 years ago by
Status: | pending → new |
---|
As you requested, I created a simple test case on the jsFiddle website. You can reproduce the the issue by following this link.
comment:3 Changed 11 years ago by
Status: | new → open |
---|
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.
comment:4 Changed 11 years ago by
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.
comment:5 Changed 11 years ago by
I've updated the test case so that it now allows to test the .offset() method along with the .css() method.
comment:6 follow-up: 7 Changed 11 years ago by
potentially related: in Firefox, .offset() does not account for -moz-transform: translate(x,y) changes, whereas chrome & Safari both account for -webkit-transform: translate().
comment:7 Changed 11 years ago by
Replying to [email protected]…:
potentially related: in Firefox, .offset() does not account for -moz-transform: translate(x,y) changes, whereas chrome & Safari both account for -webkit-transform: translate().
comment:8 Changed 11 years ago by
Replying to 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
comment:9 Changed 11 years ago by
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/
comment:10 Changed 11 years ago by
I was just going to file this. Here's my test case: http://jsfiddle.net/LcX7C/1/
comment:11 Changed 11 years ago by
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.
comment:12 Changed 11 years ago by
Resolution: | → invalid |
---|---|
Status: | open → closed |
As noted by scott.gonzalez this isn't a bug but specified behavior.
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