【发布时间】:2013-11-05 21:17:25
【问题描述】:
我正在尝试复制 Windows 8 磁贴的加载动画。似乎每个图块都有一个动画延迟,略高于其前身。正如您在下面看到的那样,我目前通过以低效的方式使用 nth-child 来实现这一点。有谁知道我可以以更有效的方式实现这一目标,以满足任意数量的 div 的需求?
.results div:nth-child(1) {
animation-delay: 0.25s;
}
.results div:nth-child(2) {
animation-delay: 0.5s;
}
.results div:nth-child(3) {
animation-delay: 0.75s;
}
.results div:nth-child(4) {
animation-delay: 1s;
}
.results div:nth-child(5) {
animation-delay: 1.25s;
}
.results div:nth-child(6) {
animation-delay: 1.5s;
}
.results div:nth-child(7) {
animation-delay: 1.75s;
}
.results div:nth-child(8) {
animation-delay: 2s;
}
【问题讨论】:
-
由于每个 CSS 预处理器都输出普通的旧 CSS,我认为不可能处理无限数量的元素。另一方面,Javascript...
-
我认为它可以与知道如何使用 SASS 的人一起 - 看到这个外观并说出序列 thesassway.com/advanced/math-sequences-with-sass / en.wikipedia.org/wiki/Look-and-say_sequence
-
唯一可行的方法是如果它也可以在 vanilla CSS 中完成。如果您愿意接受必须明确说明有多少元素,我相信您可以做到这一点。点赞,希望你能得到一个好的答案。
-
可能是混合JS来算出div的个数,然后检查之前的div动画延迟,给那个数字加上一定的时间?