HTML-Leinwand clearRect () -Methode
Beispiele
Innerhalb eines gegebenen Rechtecks leeres Rechteck:
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);
Versuchen »
Browser-Unterstützung
Internet Explorer 9, Firefox, Opera, Chrome und Safari Unterstützung clearRect () -Methode.
Hinweis: 8 und frühere Versionen von Internet Explorer unterstützt nicht das <canvas> -Element.
Definition und Verwendung
clearRect () -Methode die leere Menge von Pixeln innerhalb des Rechtecks zu spezifizieren.
JavaScript-Syntax: | Kontext .clearRect (x, y, Breite, Höhe); |
---|
Parameter Wert
参数 | 描述 |
---|---|
x | 要清除的矩形左上角的 x 坐标。 |
y | 要清除的矩形左上角的 y 坐标。 |
width | 要清除的矩形的宽度,以像素计。 |
height | 要清除的矩形的高度,以像素计。 |