Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Last active December 19, 2015 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakenickels/5941172 to your computer and use it in GitHub Desktop.
Save fakenickels/5941172 to your computer and use it in GitHub Desktop.
Simple JavaScript Animation Engine
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