昨天看到某个javascript库的动画引擎的核心,发现果不其然,说到底有两种方法:
假设
var delta = propertyValue1 - propertyValue2;
var duration = 1000ms;
var interval = 10ms
var loopCount = duration/interval;
var
1. 计算出每次增量
var loopIncrement = delta/loopCount;
setInterval(function(){propertyNew += loopIncrement},interval);
2. 利用时间戳计算
var starttime = now();
setInterval(function(){propertyNew =propertyValue1 + delta*(now() - starttime)/duration},interval);