Skip to content

Instantly share code, notes, and snippets.

@jlittlejohn
Created December 12, 2013 16:11
Show Gist options
  • Save jlittlejohn/7930549 to your computer and use it in GitHub Desktop.
Save jlittlejohn/7930549 to your computer and use it in GitHub Desktop.
SCSS: Animate Sprite Background Using CSS
/* HTML
<div class="animation"></div>
*/
/*-- Keyframes & Animation Mixins --*/
@mixin keyframes($name) {
@-webkit-keyframes #{$name} {
@content;
}
@-moz-keyframes #{$name} {
@content;
}
@-o-keyframes #{name} {
@content;
}
@-ms-keyframes #{$name} {
@content;
}
@keyframes #{$name} {
@content;
}
}
@mixin animation($content) {
-webkit-animation: $content;
-moz-animation: $content;
-ms-animation: $content;
-o-animation: $content;
animation: $content;
}
/*-- Construct Animation --*/
@include keyframes(animate-background) {
from { background-position: 0px; }
// length of sprite
to { background-position: -500px; }
}
/* Apply Mixins & constructed animation to DOM node */
.animation {
// Dimensions of each slide
width: 100px;
height: 100px;
// sprite location
background-image: url("http://files.simurai.com/misc/sprite.png");
// attach animation - time of animation, # of slides, # of times to run
@include animation(animate-background .8s steps(10) infinite);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment