Reputation: 43
I am making incremental changes to the x and y coordinates of elements in HTML. However, the code executes so fast that the browser does not have time to keep up. I tried to add a while loop after each animation to spin for 20000000 cycles so that the browser has time to animate, but it seems that the code is skipping over the while loop entirely. Is this strategy the most optimal for delaying animation times?
Upvotes: 0
Views: 54
Reputation: 4915
You should make use of requestAnimationFrame
in order to control your update cycle.
In your case, it sounds like you would like to control the FPS.
See Controlling fps with requestAnimationFrame? for more details.
Usually, your browser tries to run animations as smooth as possible (60 FPS) but you could also lower this manually
Upvotes: 2