指定された矩形内の矩形をクリアします:
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);
Try it Yourself ❯
表中の数字は、メソッドを完全にサポートした最初のブラウザ・バージョンを指定しています。
メソッド | |||||
---|---|---|---|---|---|
clearRect() | Yes | 9.0 | Yes | Yes | Yes |
clearRect() メソッドは、指定された矩形の中から指定のピクセルをクリアします。
JavaScript 構文: | context.clearRect(x,y,width,height); |
---|
パラメータ | 説明 | Play it |
---|---|---|
x | 矩形の左上隅の x 座標 to clear | Play it ❯ |
y | 矩形の左上隅の y 座標 to clear | Play it ❯ |
width | width of the rectangle to clear, in pixels | Play it ❯ |
height | height of the rectangle to clear, in pixels | Play it ❯ |