Canvas Clear canvas 清空画布(新) - caleb531/jcanvas-docs GitHub Wiki

Clear Canvas 清空画布

This clearCanvas() clears all or any part of the canvas.
这个clearCanvas()命令会清除画布上所有或任意部分(的内容)。

A note about layers 层的注意事项

This method is not meant to be used if you are using the jCanvas Layer API, because the API handles redrawing for you in many cases, and so if you try to clear the canvas. you layers will eventually be redrawn by jCanvas when it deems necessary.
这个方法并不意味着,你要是使用了jCanvas层接口的话就要使用它,因为接口在许多种情况下都为你处理了重绘制操作,当然如果你想的话也可以试试清空画布。你的某些层,如果jCanvas视它们为必需时,最终会绘制它们。

If you want to hide a layer temporarily, use setLayer() to set the layer's visible property, then call drawLayers():
如果你想暂时隐藏一个层,使用setLayer()来把这个层的visible属性设置一下,然后再调用drawLayers()

$('canvas').setLayer('myLayerName', {
  visible: false // set to true instead to show the layer again
  //将visible设置为true,而不用(额外使用显示层的方法)再把层显示出来
}).drawLayers();

If you want to remove a layer permanently, call removeLayer() followed by drawLayers():
如果你想要永久删除一个层,那就调用removeLayer()之后,再调用drawLayers()

$('canvas').removeLayer('myLayerName').drawLayers();

Clear Entire Canvas 清除整个画布

If nothing is passed, the entire canvas is cleared.
如果不传入任何参数,那整个画布就会被清除。

$("canvas").clearCanvas()

Clear a Section 清除一部分

Clearing a section works in the same way as drawing a rectangle, with the rectangle being drawn from its center (by default).
清除一部分的工作方法与画矩形一样,使用一个(默认)从其中心开始绘制的矩形(作为参数)。

$("canvas")
.drawEllipse({
    fillStyle: "#000",
    x: 200, y: 100,
    width: 200, height: 100,
})
.clearCanvas({
    x: 200, y: 100,
    width: 50,
    height: 50
});