薩斯不提供這樣的功能。
通過使用全局變量,您可以得到相當接近的結果。但是,您使用的每個混音,包括由第三方提供的混音,都必須進行修改才能以此方式工作。
// the setup
$append-property-vals:(); // global variable
$old-append-property-vals:(); // global variable
@mixin append-property($key, $val, $separator: comma) {
$old-val: map-get($append-property-vals, $key);
@if $old-val {
$append-property-vals: map-merge($append-property-vals, ($key: append($old-val, $val, $separator))) !global;
} @else {
$append-property-vals: map-merge($append-property-vals, ($key: $val)) !global;
}
}
@mixin append-properties {
// cache the original value
$old-append-property-vals: $append-property-vals !global;
@content;
// write out the saved up properties
@each $key, $val in $append-property-vals {
#{$key}: $val;
}
// restore the original value
$append-property-vals: $old-append-property-vals !global;
}
// modify the OP's provided mixins to work
@mixin scale {
// if the vals should be comma delimited, write `comma` instead of `space` for the 3rd argument
@include append-property(transform, scale(2), space);
}
@mixin rotate {
@include append-property(transform, rotate(15deg), space);
}
// call the mixins
.myclass {
@include append-properties {
@include scale;
@include rotate;
}
}
輸出:
.myclass {
transform: scale(2) rotate(15deg);
}
這個答案生成CSS是無效的。此外,它並沒有真正回答被問到的問題。 – cimmanon
@cimmanon意外添加逗號。這也是一個SCSS的選擇 - 不是直接替代。 –
如果有問題的mixin執行其他操作並設置transform屬性,則這不會對OP有幫助。 – cimmanon