Método HTML lienzo clearRect()

❮ Referencia de lienzo HTML

Ejemplo

Borrar un rectángulo dentro de un rectángulo dado:

Su navegador no es compatible con HTML5canvastag.

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);

Compatibilidad con navegador

Los números en la tabla especifican la primera versión del navegador que soporta totalmente este método.

Method
clearRect() Yes 9.0 Yes Yes Yes

Definición y uso

El método clearRect() borra los píxeles especificados dentro de un rectángulo dado.

Sintaxis de JavaScript: contexto .clearRect( x,y,ancho,alto );

Valores paramétricos

Parameter Description Play it
x The x-coordinate of the upper-left corner of the rectangle to clear
y The y-coordinate of the upper-left corner of the rectangle to clear
width The width of the rectangle to clear, in pixels
height The height of the rectangle to clear, in pixels

❮ Referencia de lienzo HTML