How to determine the best “framerate” (setInterval delay) to use in a JavaScript animation loop?

后端 未结 5 915
逝去的感伤
逝去的感伤 2020-11-28 10:24

When writing a JavaScript animation, you of course make a loop using setInterval (or repeated setTimeout). But what is the best delay to use in the setInterval/setTimeout ca

5条回答
  •  囚心锁ツ
    2020-11-28 10:59

    The number told by fbogner have been tested. The browsers throttle the js-activity to a certain degree to be usable every time.

    If your javascript would be possible to run every 5msec the browser runtime would have much less cpu time to refresh the rendering or react on user input (clicks) because javascript-execution blocks the browser.

    I think the chrome-devs allow you to run your javascript at much shorter intervals than the other browsers because their V8-Javascript-Engine compiles the JavaScript and therefore it runs faster and the browser will noch be blocked as long as with interpreted js-code.

    But the engine is not only so much faster to allow shorter intervals the devs have certainly tested which is the best possible shortest interval to allow short intervals and don't blocking the browser for to long

提交回复
热议问题