Question

I used JQuery UI to make a button that hides a div on the page, and shows another.

I have a wrapper div that has 2 visible divs and 1 hidden div inside. The first visible div never moves. div 2 is hidden and div3 comes out when I press a button. When I press the button, div 2 and div 3 "drops" out/in of the screen. During this animation in Chrome, their position gets messed up.

This problem does not happen in IE or Firefox.

I believe the problem could be:

-either on float:right in div2 and div3, OR

-display:none on div3, because the broken animation seems to happen where the div3 would be, if it was visible.

I need both divs to be on the right, so I need to keep the float:right, if possible.

Here is a code example and link to jsfiddle: (please use Chrome)

http://jsfiddle.net/mZtWY/4/

    #wrapper {
        width: 300px;
        height: 150px;
        border: 1px solid black;
    }
    #box1 {
        width: 150px;
        height: 100px;
        border: 1px solid blue;
        display: inline-block;
    }
    #box2 {
        width: 120px;
        height: 120px;
        border: 1px solid yellow;
        float: right;
        display: inline-block;
    }
    #box3 {
        width: 120px;
        height: 120px;
        border: 1px solid red;
        float: right;
        display: inline-block;
        display:none;
    }

Thank you in advance if you took the time to read through all this!

Was it helpful?

Solution

I was able to fix your problem. If you read my comment on your initial post, the inline-block property was fooling you a little. If you removed that, then you see that the yellow box, before clicking the button, now is positioned where the box was sliding down then right to. So when jQuery fired the event, for some reason it thought the position was at that spot and told it to start the animation there. What you needed to do was make box1 float left and box2 and box3 float right. Then right under those 3 divs, add another div. This div is a "clear" div. Basically it informs the floated elements how to align. Here is my modified JSFiddle:

http://jsfiddle.net/6yj8f/

EDIT: I added the wrong JSFiddle link.

Here is my code:

HTML:

<body>
    <input type = "button" id = "button" value = "button">
    <div id = "wrapper">
        <div id = "box1"></div>
        <div id = "box2"></div>
        <div id = "box3"></div>
        <div class="clear"></div>
    </div>
</body>

CSS:

.clear {
    clear: both;
}

#wrapper {
    width: 300px;
    height: 150px;
    border: 1px solid black;
}

#box1 {
    width: 150px;
    height: 100px;
    border: 1px solid blue;
    display: block;
    float: left;
}

#box2 {
    width: 120px;
    height: 120px;
    border: 1px solid yellow;
    float: right;
    display: block;
}
#box3 {
    width: 120px;
    height: 100px;
    border: 1px solid red;
    float: right;
    display: none;
}

jQuery:

$(document).ready(function(){
$('#button').click(function(){
        $('#box2').hide( "drop", { direction: "right" }, 300, function () { 
            $('#box3').show( "drop", { direction: "right" }, 300 );
        });
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top