Last active
December 19, 2015 10:29
-
-
Save fakenickels/5941172 to your computer and use it in GitHub Desktop.
Simple JavaScript Animation Engine
This file contains hidden or 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
function now(){ | |
return ( new Date ).getTime(); | |
} | |
function animate( time, fn, fps ){ | |
var start = now(), | |
intrval = fps ? 1000/fps : 20, | |
id = setInterval(function(){ | |
var diff = now() - start, p = diff/time; | |
if( p > 1 ) p = 1; | |
fn( p ); | |
if( p == 1 ) clearInterval( id ); | |
}, intrval); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment