У меня есть следующий миксин SASS:
@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 не определено. Я могу исправить это, добавив эту переменную по умолчанию в параметры миксина:
@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);
}
Но это не так чисто, как хотелось бы, есть ли ошибка в первом коде?
Большое спасибо!