HTML canvas clearRect () method
Examples
Within a given rectangle empty rectangle:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(0,0,300,150);
ctx.clearRect(20,20,100,50);
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(0,0,300,150);
ctx.clearRect(20,20,100,50);
try it"
Browser Support
Internet Explorer 9, Firefox, Opera, Chrome and Safari support clearRect () method.
Note: 8 and earlier versions of Internet Explorer do not support the <canvas> element.
Definition and Usage
clearRect () method to specify the empty set of pixels within the rectangle.
JavaScript syntax: | context .clearRect (x, y, width, height); |
---|
Parameter Value
参数 | 描述 |
---|---|
x | 要清除的矩形左上角的 x 坐标。 |
y | 要清除的矩形左上角的 y 坐标。 |
width | 要清除的矩形的宽度,以像素计。 |
height | 要清除的矩形的高度,以像素计。 |
HTML canvas Reference Manual