SOURCE

console 命令行工具 X clear

                    
>
console
let canvas = document.getElementById('canvas');
    let cxt = canvas.getContext('2d');
    cxt.strokeStyle = "#c50000";
    let distance = 0;

    let drawReact = function (left) {
        cxt.clearRect(0,0,500,500);
        cxt.beginPath();
        cxt.rect(50 + left, 50, 100, 50 );
        cxt.stroke();
        cxt.closePath();
    };
    let timer = setInterval(function () {

        drawReact(distance);
        distance ++;
        if(distance>50){
            clearInterval(timer);
        }

    }, 16)
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Document</title>
</head>
<body>
  <canvas id="canvas" width='700' height='550'>
    浏览器不支持canvas
  </canvas>
</body>
</html>
* {
  margin: 0;
  padding: 0;
}