用于确定颜色亮度的Sass函数

用于确定颜色亮度的Sass函数,sass,luminance,Sass,Luminance,我在网上找到了半打用于确定Sass中颜色亮度的函数。它们几乎一模一样,但都不起作用——都抛出了相同的错误: invalid operands for multiplication 这是我目前正在使用的功能: @function luminance($color){ $rgba: red($color), green($color), blue($color); $rgba2: (); @for $i from 1 through 3 { $rgb: n

我在网上找到了半打用于确定Sass中颜色亮度的函数。它们几乎一模一样,但都不起作用——都抛出了相同的错误:

invalid operands for multiplication
这是我目前正在使用的功能:

@function luminance($color){
    $rgba: red($color), green($color), blue($color);
    $rgba2: ();

    @for $i from 1 through 3 {
        $rgb: nth($rgba, $i);
        $rgb: $rgb / 255;
        $rgb: if($rgb < .03928, $rgb / 12.92, pow(($rgb + .055) / 1.055, 2.4));
        $rgba2: append($rgba2, $rgb);
    }

    @return (.2126 * nth($rgba2, 1) + .7152 * nth($rgba2, 2) + 0.0722 * nth($rgba2, 3))*100;
}
@功能亮度($color){
$rgba:红色($color)、绿色($color)、蓝色($color);
$rgba2:();
@从1到3的$i{
$rgb:N($rgba$i);
$rgb:$rgb/255;
$rgb:if($rgb<.03928,$rgb/12.92,pow($rgb+.055)/1.055,2.4));
$rgba2:追加($rgba2,$rgb);
}
@回报率(.2126*n($rgba2,1)+.7152*n($rgba2,2)+0.0722*n($rgba2,3))*100;
}

错误是指该函数中的最后一行。我尝试过的所有其他函数(以相同的基本方式工作)都会抛出相同的错误。

无法重现:您缺少了
pow
函数,它不是Sass核心的一部分。所以你基本上是想把一个字符串除以一个数字。默认情况下,SassMeister包括Compass(它有一个
pow
功能),因此解释了为什么它在SassMeister中工作,但不在您这边工作。您也可以在internet上的某个位置仅使用
pow
功能,而不必为此仅使用指南针。