requestAnimationFrame at a limited framerate

前端 未结 3 1191
梦毁少年i
梦毁少年i 2020-12-30 04:16

As I understand it, usage of the JS requestAnimationFrame API is intended for cases where the framerate isn\'t in need of being controlled, but I have a use cas

3条回答
  •  無奈伤痛
    2020-12-30 05:10

    Yoshi's answer is probably the best code solution to this problem. But still I'll mark this answer as correct, because after some research I basically found that my question was invalid. requestAnimationFrame is really meant to keep frame rates as high as possible, and it optimizes for scenarios where animation is meant to be kept consistent and smooth.

    Worth noting though is that you don't need requestAnimationFrame to get optimization (even though rAF was touted as a great performance booster) since browsers still optimize regular drawing of a . For example, when a tab isn't focused, Chrome for one stops drawing its canvases.

    So my conclusion was that this question was invalid. Hope this helps anyone who was wondering something similar to me.

提交回复
热议问题