2013-01-12 14 views
1

參照混入有沒有辦法通過參照SASS其他功能或混入傳遞函數或混入,然後調用引用的函數或混入?傳遞函數或SASS

例如:

@function foo($value) { 
    @return $value; 
} 

@mixin bob($fn: null) { 
    a { 
     b: $fn(c); // is there a way to call a referenced function here? 
    } 
} 

@include bob(foo); // is there any way I can pass the function "foo" here? 

回答

3

功能和混入不一流在薩斯,這意味着像您可以與變量,你不能圍繞它們作爲參數傳遞。

薩斯3.2及以上

你可以得到最接近的是與@content指令(薩斯3.2+)。

@mixin foo { 
    a { 
     @content; 
    } 
} 

@include bob { 
    b: foo(c); // this replaces `@content` in the foo mixin 
} 

唯一需要注意的是,@content不能看到什麼是你的mixin內。換句話說,如果c僅在bob mixin中定義,它基本上不存在,因爲它不在範圍內考慮。

薩斯3.3及更高版本

3.3開始,您可以使用call()功能,但它僅適用於具有的功能,而不是混入使用。這需要傳遞包含函數名稱的字符串作爲第一個參數。

@function foo($value) { 
    @return $value; 
} 

@mixin bob($fn: null) { 
    a { 
     b: call($fn, c); 
    } 
} 

@include bob('foo');