Created
December 12, 2013 16:11
-
-
Save jlittlejohn/7930549 to your computer and use it in GitHub Desktop.
SCSS: Animate Sprite Background Using CSS
This file contains hidden or 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
/* 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