Sass错误“功能X没有@return完成”

时间:2013-05-08 05:39:13

标签: sass

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

1 个答案:

答案 0 :(得分:1)

Sass告诉你错误信息中没有这个原因的原因:功能反面完成没有@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个条件:top,right,bottom,left。有一个被忽视的第五个选项:以上都没有。如果只有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;
}