Ticket #7774 (closed bug: invalid)
set offset lead to show() method failed
| Reported by: | mrbbljc@… | Owned by: | mrbbljc@… |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.6 |
| Component: | unfiled | Version: | 1.4.4 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description (last modified by jitter) (diff)
$( "#ContactBtn" ).bind( "click", function(evt) {
var offset = $(this).offset(),
newOff = {};
newOff.left = offset.left - 250;
newOff.top = offset.top - 350;//
$( "#ContactPanel" ).offset( newOff ).show();
});
when I click ContactBtn,first it show,but when I use ("#ContactBtn").hide() It must click twice to show the div panel; I'm not sure it's a bug; But,
$( "#ContactBtn" ).bind( "click", function(evt) {
var x, y;
if( typeof window.event != 'undefined' ){
x = evt.clientX;
y = evt.clientY;
} else {
x = evt.pageX;
y = evt.pageY;
}
$( "#ContactPanel" ).css( "top", y - 350 + "px" )
.css( "left", x - 250 + "px" )
.show();
});
It's work; I'm sorry my poor English;
Change History
comment:2 Changed 2 years ago by anonymous
test url: http://jsfiddle.net/sPMGM/1/ I found that I click the button div every time,the offset() method's final result different. I use IE8,and set overflow hidden,so it disappear;
comment:3 Changed 2 years ago by mrbbljc@…
- Status changed from pending to new
Test url: http://jsfiddle.net/sPMGM/1/
comment:4 Changed 2 years ago by jitter
- Status changed from new to closed
- Resolution set to invalid
- Description modified (diff)
Thanks for reporting back with and providing a test case!
This isn't a bug in jQuery. The offset() documentation states
jQuery does not support getting the offset coordinates of hidden elements.
which explains your problems. That it works the first time is only a "coincidence" because at that time top/left are 0. Just change .ContactPanel top/left to something different from 0px and then it also won't work on the first click.
The correct way to go about this is to use .css()
working test case based on your code
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Please provide a reduced test case on jsFiddle demonstrating this issue. Also, please tells us what browser you experienced this issue in.