CSS sprite sheet animation

by Alex

HTML

<img src="http://files.simurai.com/misc/sprite.png" />
<div class="hi"></div>
<div class="hi2"></div>

CSS

.hi:before {
    content:"";
    display:block;
    width: 50px;
    height: 72px;
    background-image: url("http://files.simurai.com/misc/sprite.png");
    
    -webkit-animation: play .8s steps(10) infinite;

}

@-webkit-keyframes play {
   from { background-position:    0px; }
     to { background-position: -500px; }
}

@-moz-keyframes play {
   from { background-position:    0px; }
     to { background-position: -500px; }
}

@-ms-keyframes play {
   from { background-position:    0px; }
     to { background-position: -500px; }
}

@-o-keyframes play {
   from { background-position:    0px; }
     to { background-position: -500px; }
}

@keyframes play {
   from { background-position:    0px; }
     to { background-position: -500px; }
}

.hi2:before {
    content:"";
    display:block;
    width: 50px;
    height: 72px;
    background-image: url("http://files.simurai.com/misc/sprite.png");
    
    -webkit-animation: playepara .8s steps(9) forwards;

}

@-webkit-keyframes playepara {
   from { background-position:    0px; }
     to { background-position: -450px; }
}

JavaScript

// Sprite Sheet animation with CSS3 using the steps() feature.
// To change the speed, just edit the ".8s" animation time.

// Inspired by Lea's typing animation: http://t.co/9RPMmV7