javascript
  • jquery
  • html
  • css
  • animation
  • 2014-11-03 82 views -3 likes 
    -3

    我想實現一個很好的動畫,但是我有點卡住使用CSS只實現我想要的效果。目前,我正在使用animate.css爲新元素設置動畫,但舊元素不會優雅地移動,因爲我沒有其他動畫。優雅地動畫一堆divs

    這是一個http://jsfiddle.net/tcq8kuy6/1/說明我的動畫的當前狀態。

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

    爲什麼不使用CSS3 translateY()添加一個新元素之前,先將你的一堆子元素放在一個點上,因爲這些子元素的高度已知 – Kiwi1 2014-11-03 20:52:55

    +0

    在這種情況下,它已知,但divs可以有不同的尺寸。我無法找到一種方法來簡單地說,插入前滑下100px,這是我想要實現的。 – Astronaut 2014-11-03 21:00:25

    回答

    1

    fiddle

    爲了使這項工作我做了幾件事情: -

    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); 
    

    希望這H ELPS。

    +0

    嗨格雷厄姆感謝小提琴,你可以向我解釋什麼隱藏功能呢? – Astronaut 2014-11-03 21:11:14

    +1

    當你預先設定div時,它是可見的,所以有40px的高度 - 這會使現有的項目向下抽搐 - 所以'.hide()'就是這樣做的 - 它隱藏了你插入的div(想想.hide設置CSS顯示:無),沒有它你會體驗所有現有的div快速下降,然後在某些瀏覽器中恢復。 – 2014-11-03 21:13:26

    +0

    謝謝你的解釋! – Astronaut 2014-11-03 21:15:11

    相關問題