我想知道是否有在CSS中使用相同的關鍵動畫元素有延遲。例如,我有一個具有相同類的元素列表,並且每個元素都使用關鍵動畫,但每個元素的延遲時間爲1秒,因此它們不會同時播放,而是一個接一個地播放。如果你能在CSS中做到這一點可能有人告訴我如何做到這一點的的jsfiddle請和留言,感謝從KDM一個接一個地在HTML元素上單獨的鍵動畫
0
A
回答
1
您可以通過只調用了不同的延遲動畫做到這一點很簡單的CSS
* { animation: $name $duration $timing-function; } // all elements you want get animation called
.element { animation-delay: 100ms; } // set the delay here
.other-element { animation-delay: 200ms; } // set it again for different delays
如果你不能爲每一個你想要有不同延遲的元素指定一個不同的類,那麼只需要使用n-child選擇器。
nth-child(odd) { animation-delay: 100ms; }
nth-child(even) { animation-delay: 200ms; }
您還可以在SASS/Less中使用mixin執行此操作,我使用不同的屬性調用動畫。
@mixin animation($name, $duration: 1000ms, $iterations: infinite, $timing-function: ease, $delay: 0ms) {
-webkit-animation: $name $duration $iterations $timing-function $delay;
-moz-animation: $name $duration $iterations $timing-function $delay;
-o-animation: $name $duration $iterations $timing-function $delay;
animation: $name $duration $iterations $timing-function $delay;
}
必須指定$ name,它指的是要運行的動畫關鍵幀。所有其他屬性都有默認值,以防未指定。在你的情況下,只要使用該mixin在你想要的任何元素,但給每個不同的延遲值。
1
如果你想在動畫序列的元素,你可以使用這樣的事情:
@mixin sequenceAnimate($animationName, $elements: 1, $animationDuration: 1s, $animationDelay: 1s)
@for $i from 1 through $elements
&:nth-of-type(#{$i})
-webkit-animation-name: $animationName
-webkit-animation-duration: $animationDuration
-webkit-animation-delay: $animationDelay * $i
相關問題
- 1. 一個接一個對齊html元素
- 2. jquery動畫一個接一個的元素
- 3. jquery一個接一個地動畫?
- 4. 一個接一個地播放動畫
- 5. 背景上的動畫單個元素
- 6. jQuery懸停動畫在一個數組中的單個元素
- 7. 在單個元素上設置多個動畫時,一個一個地觸發它們
- 8. SMIL to CSS動畫:單個元素上的多個動畫
- 9. 單獨一個元素的選擇器?
- 10. 在單獨的行上打印一行中的每個元素?
- 11. jQuery動畫單個元素
- 12. 如何使用jQuery一個接一個地動畫單詞
- 13. 從一個單獨的文件中更改html元素
- 14. Actionscript:一個接一個地自動排列元素
- 15. 改變一個div的類與一個單獨的元素
- 16. 的jQuery - 動畫兩個元素一舉
- 17. 爲一個UIView,做兩個動畫,一個接一個地
- 18. 在另一個元素的動畫完成之前使用jquery啓動一個元素的動畫
- 19. 一個接一個地在不同的圖像上使用一系列動畫
- 20. 用動畫將元素從一個父元素移到另一個元素
- 21. touchstart上的一個元素,拖動,touchend另一個元素
- 22. 打開一個單獨的元素點擊一個選項
- 23. 作爲在元素動畫,在另一個動畫
- 24. 一個接一個的兩個動畫
- 25. JQuery插件動畫移動一個DOM元素到另一個
- 26. 動態繪製一個畫布元素
- 27. 在HTML中包裝一個元素與另一個元素
- 28. 如何在元素懸停時動畫另一個元素?
- 29. 在同一個HTML文件中使用兩個畫布元素
- 30. RaphaelJS:如何在另一個元素動畫完成後動畫元素?