Canvas clearRect() methode
Definitie en gebruik
clearRect()
Method wist de specifieke pixels binnen de gegeven rechthoek.
Voorbeeld
Wis een rechthoek binnen een gegeven rechthoek:
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);
Syntax
context.clearRect(x,y,width,height);
Parameterwaarde
Parameter | Beschrijving |
---|---|
x | De x-coördinaat van de linkerbovenhoek van het te wissen rechthoek |
y | De y-coördinaat van de linkerbovenhoek van het te wissen rechthoek |
width | The width of the rectangle to be cleared, in pixels |
height | The height of the rectangle to be cleared, in pixels |
Browser support
The numbers in the table indicate the first browser version that fully supports this property.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.