<canvas width="1000" height="500" style="position: absolute;"></canvas>
<script>
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
var x = 20;
ctx.strokeStyle="red";
ctx.beginPath();
ctx.arc(x, 250, 15, 0, 2*Math.PI, true);
ctx.closePath();
ctx.stroke();
var animate = function () {
ctx.clearRect(0,0, 1000, 500);
x+= 5;
ctx.beginPath();
ctx.arc(x, 250, 15, 0, 2*Math.PI, true);
ctx.closePath();
ctx.stroke();
if (x < 1000) {
requestAnimationFrame(animate);
}
};
setTimeout(animate , 2000);
</script>