Metoda HTML canvas strokeRect()
Przykład
Narysuj prostokąt o wymiarach 150*100 pikseli:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.strokeRect(20, 20, 150, 100);
Obsługa przeglądarki
Liczby w tabeli określają pierwszą wersję przeglądarki, która w pełni obsługuje tę metodę.
Method | |||||
---|---|---|---|---|---|
strokeRect() | Yes | 9.0 | Yes | Yes | Yes |
Definicja i użycie
Metoda strokeRect() rysuje prostokąt (bez wypełnienia). Domyślny kolor obrysu to czarny.
Porada: Użyj właściwości strokeStyle , aby ustawić kolor, gradient lub deseń w celu nadania stylu pociągnięcia.
Składnia JavaScript: | kontekst .strokeRect( x,y,szerokość,wysokość ); |
---|
Wartości parametrów
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 |
❮ Odniesienie do płótna HTML