Método strokeRect() da tela HTML

❮ Referência de tela HTML

Exemplo

Desenhe um retângulo de 150*100 pixels:

Seu navegador não suporta a tag HTML5canvastag.

JavaScript:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.strokeRect(20, 20, 150, 100);

Suporte ao navegador

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

Method
strokeRect() Yes 9.0 Yes Yes Yes

Definição e uso

O método strokeRect() desenha um retângulo (sem preenchimento). A cor padrão do traço é preto.

Dica: Use a propriedade strokeStyle para definir uma cor, gradiente ou padrão para estilizar o traçado.

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

Valores de parâmetro

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

❮ Referência de tela HTML