elegantly animate a stack of divs

2019-09-21 18:57发布

I am trying to achieve a nice animation, however I am a bit stuck using CSS only to achieve the effect that I want. Currently I am using animate.css to animate new elements in, but the old element dont move gracefully, since I have no further animation.

Here is a http://jsfiddle.net/tcq8kuy6/1/ illustrating the current state of my animation.

setInterval(function(){
    var newbox = "<div class='child animated bounceInDown'></div>"
$('.container').prepend(newbox);

}, 2000);

1条回答
Fickle 薄情
2楼-- · 2019-09-21 19:31

fiddle

In order to make this work I did a couple of things:-

1 CSS

 .child {
 width: 40px;
 height: 40px;
 display: block; //inline block results in jerkiness when inserting items 
 margin:2px; //added margin to compensate for inline-block becoming block.
 border: 1px solid #AAAAAA;
 }

2 JS

setTimeout(function(){
    var newbox = "<div class='child  animated bounceInDown'></div>"
    $(newbox).prependTo('.container').hide().slideDown(500);//notice that I prepend to the container, then hide the 'newbox' and then slide it down -> this gives the desired effect.

}, 2000);

Hopefully that helps.

查看更多
登录 后发表回答