Side navigation
#7774 closed bug (invalid)
Opened December 14, 2010 06:23AM UTC
Closed December 14, 2010 12:18PM UTC
Last modified March 13, 2012 08:47PM UTC
set offset lead to show() method failed
Reported by: | mrbbljc@126.com | Owned by: | mrbbljc@126.com |
---|---|---|---|
Priority: | undecided | Milestone: | 1.6 |
Component: | unfiled | Version: | 1.4.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
$( "#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;
Attachments (0)
Change History (4)
Changed December 14, 2010 06:49AM UTC by comment:1
owner: | → mrbbljc@126.com |
---|---|
status: | new → pending |
Changed December 14, 2010 07:43AM UTC by comment:2
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;
Changed December 14, 2010 07:46AM UTC by comment:3
status: | pending → new |
---|
Test url:[http://jsfiddle.net/sPMGM/1/]
Changed December 14, 2010 12:18PM UTC by comment:4
description: | $("#ContactBtn").bind("click",function(evt){ \ var offset = $(this).offset(); \ var 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; → {{{ \ $( "#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; |
---|---|
resolution: | → invalid |
status: | new → closed |
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 provide a reduced test case on jsFiddle demonstrating this issue. Also, please tells us what browser you experienced this issue in.