0

我正在为 SCSS 构建一个 mixin 我想知道是否可以添加一个附加值,具体取决于一个参数。这是我尝试过的。一切正常,但 @if 条件:

@mixin fontFace( $fontName, $path: "", $weight: normal, $style: none, $fileName: $fontName, $svg:0 ) {
    @font-face {
      font-family: $fontName;
        src: url("#{$path}#{$fileName}.eot");
        src: url("#{$path}#{$fileName}.eot?iefix") format("eot"), 
                 url("#{$path}#{$fileName}.woff") format("woff"),
                 url("#{$path}#{$fileName}.ttf") format("truetype")
                 @if $svg != 0 {
                    , url("#{$path}#{$fileName}.svg##{$fileName}") format("svg");
                 }else{
                    ;
                 }
      font-weight: $weight;
      font-style: $style;
    }
}
4

1 回答 1

1

以下情况如何:

@mixin fontFace( $fontName, $path: "", $weight: normal, $style: none, $fileName: $fontName, $svg: false ) {
    $src: url("#{$path}#{$fileName}.eot?iefix") format("eot"), 
          url("#{$path}#{$fileName}.woff") format("woff"),
          url("#{$path}#{$fileName}.ttf") format("truetype");

    @if $svg == true {
        $src: $src, 
                url("#{$path}#{$fileName}.svg##{$fileName}") format("svg");
    }

    @font-face {
        font-family: $fontName;
        src: url("#{$path}#{$fileName}.eot");
        src: $src;
        font-weight: $weight;
        font-style: $style;
    }
}
于 2012-06-25T11:51:58.993 回答