Replace setTimeout with requestAnimationFrame.