CSS sprite sheet animation
by lasha
HTML
<img src="http://files.simurai.com/misc/sprite.png" />
<div class="hi"></div>
CSS
.hi {
width: 50px;
height: 72px;
background-image: url("http://files.simurai.com/misc/sprite.png");
/* -webkit-animation: play .8s steps(10) infinite; */
}
/* .hi:hover { -webkit-animation: play .8s steps(10) infinite; } */
.hi.active { -webkit-animation: play .8s steps(10) infinite; }
@-webkit-keyframes play {
from { background-position: 0px; }
to { background-position: -500px; }
}
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
$(".hi").on("click", function(e){
$(this).toggleClass("active");
});