// โญ๏ธ 1. request first frame
requestAnimationFrame(animate);
// render loop
// - t1: current timestamp (in ms)
// - t0: last timestamp
function animate(t1, t0) {
if (!t0) t0 = t1;
// โญ๏ธ 2. update the animation ...
// ...
// โญ๏ธ 3. request next frame if necessary
if (!done) requestAnimationFrame(t2 => animate(t2, t1));
}
let id = requestAnimationFrame(animate);
// ...
cancelAnimationFrame(id);