Método clearRect() da tela HTML

❮ Referência de tela HTML

Exemplo

Limpe um retângulo dentro de um determinado retângulo:

Seu navegador não suporta a tag 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);

Suporte ao navegador

Os números na tabela especificam a primeira versão do navegador que oferece suporte total ao método.

Method
clearRect() Yes 9.0 Yes Yes Yes

Definição e uso

O método clearRect() limpa os pixels especificados dentro de um determinado retângulo.

Sintaxe JavaScript: context .clearRect( x,y,largura,altura );

Valores de parâmetro

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

❮ Referência de tela HTML