Lennakim

I am lennakim

0%

在scss中使用变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14

//定義方法 animation-delay-n
@mixin animation-delay-seconds($n){
&:nth-child(#{$n}){
animation-delay: #{$n*2}s;
}
}

div {
@include animation-delay-seconds(1);
@include animation-delay-seconds(3);
@include animation-delay-seconds(5);
}

生成的css 如下:

1
2
3
4
5
6
7
8
9
10
11
12
div:nth-child(1) {
animation-delay: 2s;
}

div:nth-child(3) {
animation-delay: 6s;
}

div:nth-child(5) {
animation-delay: 10s;
}

资料

use-nth-child-value-as-a-sass-variable

select-every-nth-element-in-css

sass-meister