Confuse About Using Javascript Setinterval To Do Animate Job
I try to use setInterval to achieve animate effect in javascript, I want a div's width increase 200px(the box's origin width is 100px) in 1000ms: var MAX = 300, duration = 1000; va
Solution 1:
The solution @Ken said is an available one, but the browser don't support requestAnimationFrame
, it could't work;
The mistake I made in my code is, what I calculate the increasement is increased per 1ms, but the timer execute my animate function per 4ms (according to the minimum delay).
So for some insurance,we better set the timer delay by hand, like 13ms
(the interval in jquery animation), and the increasement should be:
var inc = parseFloat( MAX / duration ) * 13;
use the 13 * perOneMillisecond
as the increasement for matching the 13ms
interval
Here is the Demo, then you can check time cost almost as the jquery(but still slower some, why?)
Post a Comment for "Confuse About Using Javascript Setinterval To Do Animate Job"