有没有办法将外部变量导入mixins?
我想从mixin参数中生成一个变量名
然后从外部源调用它。这有意义吗?
/* Striped status bar variables ******************************************/
$greyFirstGradientStartColor: #999999;
$greyFirstGradientEndColor: #d3cfcf;
$greySecondGradientStartColor: #ababab;
$greySecondGradientEndColor: #595959;
@import variables.scss
[...]
@mixin gradient-repeating($color, $deg, $firstWidth, $space, $secondWidth){
background-image:
repeating-linear-gradient(
$deg,
$(#{$color}FirstGradientStartColor),
$(#{$color}FirstGradientEndColor) $firstWidth+px,
$(#{$color}SecondGradientStartColor) ($firstWidth+$space)+px,
$(#{$color}SecondGradientStartColor) $secondWidth+px
);
}
@import variables.scss;
@import mixins.scss;
[...]
@include gradient-repeating(grey, -45, 20, 0, 20);
答案 0 :(得分:2)
没有。 Sass中不存在变量变量。通常使用列表或列表列表。
你的mixin可以这样写:
$grey-gradient: #999999 #d3cfcf, #ababab #595959;
@mixin gradient-repeating($color, $deg, $firstWidth, $space, $secondWidth){
$firstColor: nth($color, 1);
$secondColor: nth($color, 2);
background-image:
repeating-linear-gradient(
$deg,
nth($firstColor, 1),
nth($firstColor, 2) $firstWidth+px,
nth($secondColor, 1) ($firstWidth+$space)+px,
nth($secondColor, 1) $secondWidth+px
);
}
.foo {
@include gradient-repeating($grey-gradient, -45, 20, 0, 20);
}