Use the window.requestAnimationFrame() method if it is available.