Created
September 9, 2012 13:12
-
-
Save felixzapata/3684209 to your computer and use it in GitHub Desktop.
animacion controlada mediante un temporizador
This file contains 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
// 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