Skip to content

Instantly share code, notes, and snippets.

@philippbosch
Last active August 29, 2019 00:20
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philippbosch/5188069 to your computer and use it in GitHub Desktop.
Save philippbosch/5188069 to your computer and use it in GitHub Desktop.
Compass mixins for CSS keyframe animations
@import "compass/css3/shared";
@mixin keyframes($name) {
@-webkit-keyframes $name {
@content;
}
@-moz-keyframes $name {
@content;
}
@-ms-keyframes $name {
@content;
}
@-o-keyframes $name {
@content;
}
@keyframes $name {
@content;
}
}
@mixin animation($name, $duration, $timing-function: false, $delay: false, $iteration-count: false, $direction: false) {
@include experimental(animation-name, $name, -moz, -webkit, -o, -ms, not -khtml, official);
@include experimental(animation-duration, $duration, -moz, -webkit, -o, -ms, not -khtml, official);
@if $timing-function {
@include experimental(animation-timing-function, $timing-function, -moz, -webkit, -o, -ms, not -khtml, official);
}
@if $delay {
@include experimental(animation-delay, $delay, -moz, -webkit, -o, -ms, not -khtml, official);
}
@if $iteration-count {
@include experimental(animation-iteration-count, $iteration-count, -moz, -webkit, -o, -ms, not -khtml, official);
}
@if $direction {
@include experimental(animation-direction, $direction, -moz, -webkit, -o, -ms, not -khtml, official);
}
}
@include keyframes(pulsate) {
0% { opacity: 0; }
100% { opacity: 1; }
}
.pulsate {
@include animation(pulsate, 2s, $timing-function: linear, $iteration-count: infinite, $direction: alternate);
}
@-webkit-keyframes pulsate {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@-moz-keyframes pulsate {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@-ms-keyframes pulsate {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@-o-keyframes pulsate {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes pulsate {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.pulsate {
-webkit-animation-name: pulsate;
-moz-animation-name: pulsate;
-ms-animation-name: pulsate;
-o-animation-name: pulsate;
animation-name: pulsate;
-webkit-animation-duration: 2s;
-moz-animation-duration: 2s;
-ms-animation-duration: 2s;
-o-animation-duration: 2s;
animation-duration: 2s;
-webkit-animation-timing-function: linear;
-moz-animation-timing-function: linear;
-ms-animation-timing-function: linear;
-o-animation-timing-function: linear;
animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-ms-animation-iteration-count: infinite;
-o-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
-moz-animation-direction: alternate;
-ms-animation-direction: alternate;
-o-animation-direction: alternate;
animation-direction: alternate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment