【发布时间】:2012-01-07 19:50:48
【问题描述】:
我正在尝试通过对每个子元素应用动画来创建级联效果。我想知道是否有比这更好的方法:
.myClass img:nth-child(1){
-webkit-animation: myAnimation 0.9s linear forwards;
}
.myClass img:nth-child(2){
-webkit-animation: myAnimation 0.9s linear 0.1s forwards;
}
.myClass img:nth-child(3){
-webkit-animation: myAnimation 0.9s linear 0.2s forwards;
}
.myClass img:nth-child(4){
-webkit-animation: myAnimation 0.9s linear 0.3s forwards;
}
.myClass img:nth-child(5){
-webkit-animation: myAnimation 0.9s linear 0.4s forwards;
}
等等…… 所以基本上,我想为每个孩子制作一个动画,但有延迟。 感谢您的任何意见!
补充:也许我没有正确解释我的担忧:无论我有多少孩子,我都应该如何做到这一点。如何在不必为每个孩子写下属性的情况下做到这一点......例如,当我不知道会有多少孩子时。
【问题讨论】:
-
如何使用一些 js 元素选择器(比如 dojo.query 或 jquery)并在 for 循环中应用样式?这就是我唯一想到的......
-
是的,我想这是为每个孩子做这件事的唯一方法,而不必为每个孩子写下一节课。我认为可能会有一些新的 CSS3 属性使它成为可能,但我想我将不得不等待变量的引入......谢谢!
-
所以你在寻找某种 increment property 的 CSS 动画?像
-webkit-animation-increment这样的东西?那肯定有用,好问题。 -
@Ed-M 完全正确!我只是在看那个反增量属性,如果像这样的变量可以在任何 css 属性定义中使用,而不仅仅是“内容”属性,那就太好了……
标签: animation css delay css-selectors