0

http://jsfiddle.net/pC6fC/1/

I have two divs, one above the other. When the first animates, which it does, it slides below the other. How can I make sure that when the first animates it pushes the second downwards without having to animate both DIVs.

3 Answers 3

4

You could use margin, instead of top. As both of your divs are relatively positioned, if you set top value (i.e. 30%), it won't push your second div.

Example with margin-top: http://jsfiddle.net/pC6fC/5/

Sign up to request clarification or add additional context in comments.

Comments

3

You can do this either by animating the margin-top instead of the top, or another idea would be to put them both into a parent div and animate that one.

example1: http://jsfiddle.net/pC6fC/8/

example2: http://jsfiddle.net/pC6fC/6/

1 Comment

@powerbuoy was just adding them myself but thanks for the trouble :D
0

Here you go with modifying your jQuery a little..

  1. If you want the div to slide after your animation of box1 is completed.

    /* Slides down alert banner */ $(function(){ $(".link").click(function(){ $(".box1").animate({top:150}, 500, function () { $(".box2").css({top:150});}); }); 

    });

  2. If you want the div to slide along with animation of box1.

    /* Slides down alert banner */ $(function(){ $(".link").click(function(){ $(".box1").animate({top:150}, 500); $(".box2").css({top:150}); }); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.