小编sce*_*tti的帖子

我可以在SASS mixin中声明一个新变量吗?

我有以下SASS mixin:

@mixin gradient($start, $end, $fallback: $end, $direction: bottom) {
@if $direction == top {
    $directionOld: bottom;
} @else if $direction == right {
    $directionOld: left;
} @elseif $direction == bottom {
    $directionOld: top;
} @elseif $direction == left {
    $directionOld: right;
}

background: $fallback;
background: -webkit-linear-gradient($directionOld, $start, $end);
background:         linear-gradient(to $direction, $start, $end);
}
Run Code Online (Sandbox Code Playgroud)

这个mixin抛出一个错误,因为没有定义$ directionOld.我可以修复它默认情况下将此变量添加到mixin参数:

@mixin gradient($start, $end, $fallback: $end, $direction: bottom, $directionOld: top) {
@if $direction == top {
    $directionOld: bottom;
} @else if $direction == right …
Run Code Online (Sandbox Code Playgroud)

css variables sass mixins

7
推荐指数
1
解决办法
6080
查看次数

标签 统计

css ×1

mixins ×1

sass ×1

variables ×1