如果你想要多個參數和廠商前綴,像休耕場景:
@include transition(transform .5s linear, width .5s linear)
預計
-webkit-transition: -webkit-transform 0.5s linear, width 0.5s linear;
-moz-transition: -moz-transform 0.5s linear, width 0.5s linear;
-ms-transition: -ms-transform 0.5s linear, width 0.5s linear;
-o-transition: -o-transform 0.5s linear, width 0.5s linear;
transition: transform 0.5s linear, width 0.5s linear;
我建議你這個密新,我就發現Meaningless Writing。
代碼
@function prefix($property, $prefixes: (webkit moz o ms)) {
$vendor-prefixed-properties: transform background-clip background-size;
$result:();
@each $prefix in $prefixes {
@if index($vendor-prefixed-properties, $property) {
$property: -#{$prefix}-#{$property}
}
$result: append($result, $property);
}
@return $result;
}
@function trans-prefix($transition, $prefix: moz) {
$prefixed:();
@each $trans in $transition {
$prop-name: nth($trans, 1);
$vendor-prop-name: prefix($prop-name, $prefix);
$prop-vals: nth($trans, 2);
$prefixed: append($prefixed, ($vendor-prop-name $prop-vals), comma);
}
@return $prefixed;
}
@mixin transition($values...) {
$transitions:();
@each $declaration in $values {
$prop: nth($declaration, 1);
$prop-opts:();
$length: length($declaration);
@for $i from 2 through $length {
$prop-opts: append($prop-opts, nth($declaration, $i));
}
$trans: ($prop, $prop-opts);
$transitions: append($transitions, $trans, comma);
}
-webkit-transition: trans-prefix($transitions, webkit);
-moz-transition: trans-prefix($transitions, moz);
-o-transition: trans-prefix($transitions, o);
transition: $values;
}
這不是被接受的答案嗎? – troelskn
@troelskn在約瑟夫和他已被選爲答案後,我發佈了我的答案。我加了我的,因爲我問了同樣的問題,並在SASS文檔中找到了答案,並希望它能夠節省一些開發人員處理多餘括號的麻煩:) –
是的,它看起來像2012年添加了這個選項,我的回答是給出的。 http://chriseppstein.github.io/blog/2012/08/23/sass-3-2-is-released/ –