Update code to use requestAnimationFrame