4
我有以下SASS混入:我可以在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);
}
,因爲沒有定義$ directionOld這混入拋出一個錯誤。 我可以修復它在默認情況下將這個變量的混入PARAMS:
@mixin gradient($start, $end, $fallback: $end, $direction: bottom, $directionOld: top) {
@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);
}
但是,這並不乾淨,因爲我想,有沒有在第一代碼的任何錯誤?
非常感謝!
這有什麼代碼塊你的目標是什麼? – jbenjohnson
你看過現有的庫,而不是自己開發的mixins嗎? http://compass-style.org/ – cimmanon