Skip to content

Instantly share code, notes, and snippets.

@felixzapata
Created September 9, 2012 13:12
Show Gist options
  • Save felixzapata/3684209 to your computer and use it in GitHub Desktop.
Save felixzapata/3684209 to your computer and use it in GitHub Desktop.
animacion controlada mediante un temporizador
// http://dailyjs.com/2010/06/03/framework-part-15/
function animate() {
var box = document.getElementById('box'),
duration = 1000,
start = (new Date()).valueOf(),
finish = start + duration,
interval;
interval = setInterval(function() {
var time = (new Date()).valueOf(), frame = time > finish ? 1 : (time - start) / duration;
// The thing being animated
box.style.left = frame * 100 + 'px';
if (time > finish) {
clearInterval(interval);
}
}, 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment