【问题标题】:Reverse a list of items in sass using @for loop使用@for循环反转sass中的项目列表
【发布时间】:2020-05-14 11:48:56
【问题描述】:

这是我在 sass 中的 @for 循环:

@for $i from 1 through 10 {
  #users[data-state='unload'] li:nth-child(#{$i}n) {
    animation-delay: #{$i * 0.1}s;
  }
}

生成这个 css:

#users[data-state=loaded] li:nth-child(1n) {
  animation-delay: 0.1s;
}

#users[data-state=loaded] li:nth-child(2n) {
  animation-delay: 0.2s;
}

#users[data-state=loaded] li:nth-child(3n) {
  animation-delay: 0.3s;
}
/// etc...

我想要做的是将我的 css 读为:

#users[data-state=loaded] li:nth-child(1n) {
  animation-delay: 1s;
}

#users[data-state=loaded] li:nth-child(2n) {
  animation-delay: 0.9s;
}

#users[data-state=loaded] li:nth-child(3n) {
  animation-delay: 0.8s;
}
/// etc....

所以我想知道反转动画延迟所需的数学计算是什么,以便最后一个子元素具有入围时间,第一个子元素最长?

非常感谢 W9914420

【问题讨论】:

    标签: css math sass


    【解决方案1】:

    改变动画延迟:#{$i * 0.1}s;作为动画延迟:#{(10 - $i) * 0.1}s;

    @for $i from 0 through 10 {
      #users[data-state='unload'] li:nth-child(#{$i}n) {
        animation-delay: #{(10 - $i) * 0.1}s;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-04
      • 1970-01-01
      • 1970-01-01
      • 2019-11-19
      • 2011-06-19
      • 2020-11-21
      • 2016-06-07
      • 1970-01-01
      相关资源
      最近更新 更多