Created
July 20, 2013 18:20
-
-
Save vieron/6045967 to your computer and use it in GitHub Desktop.
Sass-mixins-for-vendor-prefixed transitions-including-properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is excellent.