title: CanvasContext.clearRect header: develop nav: api

sidebar: canvas_CanvasContext-clearRect

解释:清除画布上在该矩形区域内的内容。

方法参数

参数名 属性 必填 默认值 说明
x Number 矩形路径左上角的 x 坐标。
y Number 矩形路径左上角的 y 坐标。
width Number 矩形路径的宽度。
height Number 矩形路径的高度。

示例

在开发者工具中预览效果

扫码体验

sidebar: canvas_CanvasContext-clearRect - 图1 请使用百度APP扫码

图片示例

图片

代码示例

:::codeTab

  1. const canvasContext = swan.createCanvasContext('myCanvas');
  2. canvasContext.setFillStyle('blue');
  3. canvasContext.fillRect(0, 0, 150, 200);
  4. canvasContext.setFillStyle('blue');
  5. canvasContext.fillRect(150, 0, 150, 200);
  6. canvasContext.clearRect(30, 30, 150, 75);
  7. canvasContext.draw();

:::