Skip to content

Instantly share code, notes, and snippets.

@luanlmd
Created May 28, 2010 02:11
Show Gist options
  • Save luanlmd/416657 to your computer and use it in GitHub Desktop.
Save luanlmd/416657 to your computer and use it in GitHub Desktop.
Varnimate
function varnimate(obj,props,duration,start)
{
var now = new Date().getTime();
var atual = new Date().getTime();
//console.log(atual);
if (start+duration <= atual)
{
for (p in props)
{
obj[p] = props[p]
}
return;
}
if (start == undefined)
{
var start = new Date().getTime();
}
passou = atual-start;
passou = passou/duration;
for (p in props)
{
valor = passou*(props[p]-obj[p]);
calc = valor+obj[p];
obj[p] = calc;
}
//console.log(calc);
t = (new Date().getTime() - now);
setTimeout(function(){ varnimate(obj, props, duration, start); },16 - t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment