Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#7774 closed bug (invalid)

set offset lead to show() method failed

Reported by: [email protected] Owned by: [email protected]
Priority: undecided Milestone: 1.6
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by jitter)

$( "#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" )

It's work; I'm sorry my poor English;

Change History (4)

comment:1 Changed 12 years ago by snover

Owner: set to [email protected]
Status: newpending

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

comment:2 Changed 12 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 12 years ago by [email protected]

Status: pendingnew

comment:4 Changed 12 years ago by jitter

Description: modified (diff)
Resolution: invalid
Status: newclosed

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

Note: See TracTickets for help on using tickets.