热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在SCSS中迭代变量?

如何解决《在SCSS中迭代变量?》经验,为你挑选了1个好方法。

我正在编写一个函数来依次淡化项目...

.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;
}



1> juzraai..:

是的,你可以使用for循环和字符串插值:

@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";
}


推荐阅读
author-avatar
没得名儿呀没名字
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有