重新映射画布上的 (0,0) 位置。

    translate(x,y);

    参数 描述
    x 添加到水平坐标(x)上的值。
    y 添加到垂直坐标(y)上的值。

    var c=document.getElementById("myCanvas");
    var ctx=c.getContext("2d");
    
    ctx.translate(0,0);
    ctx.fillRect(0,0,100,50);
    
    ctx.translate(70,70);
    ctx.fillRect(0,0,100,50);

    translate() - 图1