0

我在尝试将相当复杂的渐变转换为 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%);
}
4

1 回答 1

1

Sass 在错误消息中告诉您这不起作用的原因: 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;
    }
}

您在这里只考虑 4 个条件:上、右、下、左。第五个选项被忽略了:以上都不是。如果应该只有 4 个选项,那么您需要 3 个 if/else 块和最后的返回值,这就是您的全部。

@function inverse-side($side) {
    @if $side == top {
        @return bottom;
    } 
    @else if $side == bottom {
        @return top;
    }
    @else if $side == left {
        @return right;
    }
    @return left;
}
于 2013-05-09T11:54:35.897 回答