requestAnimationFrame()
by sungsoonz
HTML
<canvas></canvas>
JavaScript
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let width = 30;
let height = 30;
function animate() {
width += 2;
height += 2;
ctx.fillRect(0, 0, width, height);
if (width > canvas.width) return;
requestAnimationFrame(animate);
}
animate();