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

后端 未结 5 897
逝去的感伤
逝去的感伤 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 11:13

    When doing loops for animations, it's best that you find a balance between the speed of the loop, and how much work needs to be done.

    For example, if you want to slide a div across the page within a second so it is a nice effect and timely. You would skip coordinates and have a reasonably fast loop time so the effect is noticeable, but not jumpy.

    So it's a trial and error thing (by having to put work, time, and browser capability into account). So it doesn't only look nice on one browser.

提交回复
热议问题