Skip to content

Instantly share code, notes, and snippets.

@jbrz0
Last active April 17, 2020 18:14
Show Gist options
  • Save jbrz0/02a9dd37587de9176a1dbdb81bb53cf4 to your computer and use it in GitHub Desktop.
Save jbrz0/02a9dd37587de9176a1dbdb81bb53cf4 to your computer and use it in GitHub Desktop.
Sass mixin to automate the CSS animation process, including vendor prefixes
//Animation mixin setup
@mixin keyframes($animation-name) {
@-webkit-keyframes #{$animation-name} {
@content;
}
@-moz-keyframes #{$animation-name} {
@content;
}
@-ms-keyframes #{$animation-name} {
@content;
}
@-o-keyframes #{$animation-name} {
@content;
}
@keyframes #{$animation-name} {
@content;
}
}
@mixin animation($str) {
-webkit-animation: #{$str};
-moz-animation: #{$str};
-ms-animation: #{$str};
-o-animation: #{$str};
animation: #{$str};
}
//Usage
// Define animation name, and properties
@include keyframes(fade-out) {
0% { opacity: 1; }
90% { opacity: 0; }
}
// Add animation to element
.element {
width: 100px;
height: 100px;
background: black;
@include animation('fade-out 5s 3');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment