【发布时间】:2013-05-08 05:39:12
【问题描述】:
我在尝试将相当复杂的渐变转换为 SASS 的 mixin 时遇到了一些麻烦,大多数渐变都很好,而且我相信我的颜色停止也是正确的,我相信这是我的 MIXIN 不允许的定位我这样做(左上,右下)。
我需要这个:
.progress.stripes.animate > .bar > span {
background-image: -webkit-gradient(
linear, left top, right bottom,
color-stop(.25, rgba(255, 255, 255, .2)),
color-stop(.25, transparent),
color-stop(.5, transparent),
color-stop(.5, rgba(255, 255, 255, .2)),
color-stop(.75, rgba(255, 255, 255, .2)),
color-stop(.75, transparent), to(transparent));
background-image: -moz-linear-gradient(-45deg, rgba(255, 255, 255, .2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, .2) 75%, transparent 75%, transparent);
}
要使用这个 mixin:
@mixin linear-gradient($gradientLine, $colorStops...) {
background-color: nth($colorStops,1);
background-image: -webkit-gradient(linear, $gradientLine, $colorStops);
background-image: -webkit-linear-gradient($gradientLine, $colorStops);
background-image: -moz-linear-gradient($gradientLine, $colorStops);
background-image: -o-linear-gradient($gradientLine, $colorStops);
background: -ms-linear-gradient($gradientLine, $colorStops);
@if length($colorStops) == 2 {
$colour1:nth($colorStops,1);
$colour2:nth($colorStops,2);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#{$colour1}', endColorstr='#{$colour2}',GradientType=0 );
}
@if length($gradientLine) == 2 {
background-image: linear-gradient(to #{inverse-side(nth($gradientLine, 1))} #{inverse-side(nth($gradientLine, 2))}, $colorStops);
} @else {
background-image: linear-gradient(to #{inverse-side($gradientLine)}, $colorStops);
}
}
这是我尝试过的,但它不起作用......
$grad: rgba(255, 255, 255, .2);
.progress.stripes.animate > .bar > span {
@include linear-gradient((left top, right bottom),$grad 25%, $transparent 25%, $transparent 5%, $grad 5%, $grad 75%, $transparent 75%);
}
【问题讨论】:
-
什么不起作用?你得到一个错误?你得到不正确的输出?
-
嗨,我收到此错误:
error scss/../shared/_mixins.scss (Line 161: Function inverse-side finished without @return) -
反面函数的代码是什么?
-
对不起,我没有意识到有人在使用:
@function inverse-side($side) { @if $side == top { @return bottom; } @else if $side == bottom { @return top; } @else if $side == left { @return right; } @else if $side == right { @return left; } } -
为什么要重新发明轮子? Compass 已经有了更强大的渐变方式:compass-style.org/reference/compass/css3/images
标签: sass