Skip to content

Instantly share code, notes, and snippets.

@vieron
Created July 20, 2013 18:20
Show Gist options
  • Save vieron/6045967 to your computer and use it in GitHub Desktop.
Save vieron/6045967 to your computer and use it in GitHub Desktop.
Sass-mixins-for-vendor-prefixed transitions-including-properties
@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;
}
@archy-bold
Copy link

This is excellent.

@raRaRa
Copy link

raRaRa commented Jan 5, 2017

Thanks for sharing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment