In JavaScript, this could have been written as such:
var state = 0;
setTimeout(function keyFrames () {
fooElement.style.backgroundPosition = '0 -' + (10*state++) + 'px';
if (state === 2) {
state = 0;
}
setTimeout(keyFrames, 500);
}, 500);
CSS3 keyframes offer a very similar functionality:
@keyframes foo { 0% { background-position: 0 0; } 50% { background-position: 0 -10px; } 100% { background-position: 0 -20px; } }
#fooElement { transition: foo 1500ms linear infinite; }
The difference is that CSS transition will utilise the timing function. Is there a way to replicate the exact JavaScript behaviour using CSS?