Use requestAnimationFrame() for smooth animations by syncing with the browser's refresh rate. Avoid heavy tasks inside the callback and only call it when needed.
requestAnimationFrame()