Si vous voulez plusieurs arguments et préfixes de vendeur, comme dans le scénario suivant :
@include transition(transform .5s linear, width .5s linear)
Attendu
-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;
Je vous suggère ce Mixin, que j'ai trouvé sur Meaningless Writing.
Code
@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;
}