javascript's animation with setTimout()
I'm reading a book called Pro Javascript Techinques(John Resig) a piece of code of the core-animation is as follwing
setTimeout(function () {
elem.style['width'] = (i / 100) * fullwith + 'px';
}, **(i + 1) * 10** );
I wonder while it should change the 'each-timeout' time to implement it
why the 'each-timeout' time should not be the same,eg:1000,It flash cons开发者_如何学Pythonequently Thanks so much~Each setTimeout registers a new timeout (all starting "now") that will fire 10ms apart, thus you do get a regular pulse every 10ms, but you queue all of them up in advance — the first timeout doesn't fire until 10ms after you've registered all of these callbacks.
Why he should do it that way when there's setInterval, I don't know — maybe interesting to find out, is it in the book?
精彩评论