JSFiddle - React, Tailwind, and code Playground
HTML
<canvas id="canvas" width="500" height="500" >
</canvas>
JavaScript
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var canvasWidth = canvas.width;
var canvasHeight = canvas.height;
var refresh = false;
var y = 0;
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();
(function animloop(){
requestAnimFrame(animloop);
redraw();
})();
function redraw() {
ctx.clearRect(0,0,canvasWidth, canvasHeight);
ctx.rect(20,y,50,50);
ctx.fillStyle="red";
ctx.fill();
y += 2;
}