我正在编写一个函数来按顺序淡入项目...
.sequenced-images li:nth-child(2) {
animation-delay: 1s;
}
.sequenced-images li:nth-child(3) {
animation-delay: 2s;
}
.sequenced-images li:nth-child(4) {
animation-delay: 3s;
}
.sequenced-images li:nth-child(5) {
animation-delay: 4s;
}
我有很多物品,并且我不想手动为下一个物品添加类。
我可以使用类似...的方法来迭代相同的规则吗?
.sequenced-images li:nth-child(i++) {
animation-delay: i++s;
}
?
答案 0 :(得分:6)
是的,您可以使用for
loop和string interpolation:
@for $i from 2 through 5 {
.sequenced-images li:nth-child(#{$i}) {
animation-delay: '#{$i - 1}s';
}
}
这将导致:
.sequenced-images li:nth-child(2) {
animation-delay: "1s";
}
.sequenced-images li:nth-child(3) {
animation-delay: "2s";
}
.sequenced-images li:nth-child(4) {
animation-delay: "3s";
}
.sequenced-images li:nth-child(5) {
animation-delay: "4s";
}