javascript - Showing an invisible div after jquery animate - Stack Overflow

So I'm trying to figure out how to show an invisible div after an animation on jquery. Here's

So I'm trying to figure out how to show an invisible div after an animation on jquery. Here's the code to show the div:

$('#box_green')
    .css({
        visibility: "visible",
        opacity: 0
    })
    .fadeIn('slow')
;

the css which also makes the div invisible:

div#box_green{
    background-image:url(../images/bg_stripe_green.png);
    background-repeat:repeat;
    width: 478px;
    height:300px;
    position:absolute;
    top:249px;
    z-index:20;
    visibility:hidden;
}

and the animation on click:

  $(document).ready(function(){

$("#menu_h, #menu_p, #menu_q, #menu_b, #menu_c").one('click', function(){
    $("#menu_h").animate({"left": "+=419px"}, "slow");
    $("#menu_p").animate({"left": "+=313px"}, "slow");
    $("#menu_q").animate({"left": "+=210px"}, "slow");
    $("#menu_b").animate({"left": "+=104px"}, "slow");
    $("#menu_c").animate({"left": "+=0px"}, "slow");
    $("#menu_h, #menu_p, #menu_q, #menu_b, #menu_c").unbind('click');
 });

});

how can I make it that the box_green div shows after the #menu_h animation is done? and lets say that I have also a hidden #box_yellow div, how can I make it visible (with the same effect as the box_green div) after fading out the box_green again (letting it be invisible again). I actually have 5 divs (box_green and box_yellow are 2 of them) that need to have that "turn currently displayed div off and show div clicked" event.

So I'm trying to figure out how to show an invisible div after an animation on jquery. Here's the code to show the div:

$('#box_green')
    .css({
        visibility: "visible",
        opacity: 0
    })
    .fadeIn('slow')
;

the css which also makes the div invisible:

div#box_green{
    background-image:url(../images/bg_stripe_green.png);
    background-repeat:repeat;
    width: 478px;
    height:300px;
    position:absolute;
    top:249px;
    z-index:20;
    visibility:hidden;
}

and the animation on click:

  $(document).ready(function(){

$("#menu_h, #menu_p, #menu_q, #menu_b, #menu_c").one('click', function(){
    $("#menu_h").animate({"left": "+=419px"}, "slow");
    $("#menu_p").animate({"left": "+=313px"}, "slow");
    $("#menu_q").animate({"left": "+=210px"}, "slow");
    $("#menu_b").animate({"left": "+=104px"}, "slow");
    $("#menu_c").animate({"left": "+=0px"}, "slow");
    $("#menu_h, #menu_p, #menu_q, #menu_b, #menu_c").unbind('click');
 });

});

how can I make it that the box_green div shows after the #menu_h animation is done? and lets say that I have also a hidden #box_yellow div, how can I make it visible (with the same effect as the box_green div) after fading out the box_green again (letting it be invisible again). I actually have 5 divs (box_green and box_yellow are 2 of them) that need to have that "turn currently displayed div off and show div clicked" event.

Share Improve this question asked Nov 14, 2009 at 9:13 BrunoBruno 1451 gold badge3 silver badges9 bronze badges 3
  • You don't need to unbind if you're using the one function. Also, your question is terribly confusing. Why are you hiding #box_green again? – Richard Nguyen Commented Nov 14, 2009 at 10:06
  • think of it as an image with information on subject X when I click on X on the menu this image should appear (with the jquery effect) it stays hidden because the menu takes the whole content area until someone clicks on the menu option X, then the whole menu slides to the right leaving enough space for the image (box_green content) to show up. – Bruno Commented Nov 14, 2009 at 10:36
  • the idea is to keep not one but five divs hidden, each one is a menu content, and they should only show up when the menu option is clicked on – Bruno Commented Nov 14, 2009 at 10:38
Add a ment  | 

2 Answers 2

Reset to default 5

You will need to implement callback.

From http://docs.jquery./Effects/animate#examples

An example of using a callback function. The first argument is an array of CSS properties, the second specifies that the animation should take 1000 milliseconds to plete, the third states the easing type, and the fourth argument is an anonymous callback function.

$("p").animate({
       height:200, width:400, opacity: .5
    }, 1000, "linear", function(){alert("all done");} );

Replace function(){alert("all done");} with your own function to made something appear, disappear, anything... :P

You can also use the show and hide functions, rather than play with the CSS of the element, or even toggle if you show/hide the same element.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745380443a4625199.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信