request animation frame
Request animation frame lets you line-up changes for the next window paint.
function update() {
// Animate elements here
window.requestAnimationFrame(update);
}
}
window.requestAnimationFrame(update);
copy