Last active
April 17, 2020 18:14
-
-
Save jbrz0/02a9dd37587de9176a1dbdb81bb53cf4 to your computer and use it in GitHub Desktop.
Sass mixin to automate the CSS animation process, including vendor prefixes
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
//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