【发布时间】:2019-11-12 12:37:45
【问题描述】:
我正在尝试编写一个 SASS mixin 来动态循环遍历元素中的项目数,然后应用自定义动画。
// MIXIN
@mixin staggerAnimation($el: $animated-elem) {
@for $i from 1 through 4 {
#{$el}:nth-child( #{$i} ) {
@content
}
}
}
// Usage from external SASS file
$animated-elem: '.item';
@include staggerAnimation($animated-elem) {
// This property needs to be different based on the usage
animation: FadeIn 1s #{$el * 0.35}s ease 1 both;
}
【问题讨论】:
-
$el * 0.35应该做什么? -
它应该增加动画延迟。在此示例中,我正在创建元素的交错动画
-
那么,不应该是
$i而不是$el吗?由于$el采用$animated-elem的值,这是一个字符串(选择器),因此您无法从中增加任何内容。但是,对于$i,问题仍然存在,因为您无法将变量从@mixin传递给@content。但是,您可以使用全局变量,请查看this。