Płótno HTML Metoda fillRect()
Przykład
Narysuj wypełniony prostokąt o wymiarach 150*100 pikseli:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillRect(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 | |||||
---|---|---|---|---|---|
fillRect() | Yes | 9.0 | Yes | Yes | Yes |
Definicja i użycie
Metoda fillRect() rysuje „wypełniony” prostokąt. Domyślny kolor wypełnienia to czarny.
Porada: Użyj właściwości fillStyle , aby ustawić kolor, gradient lub deseń używany do wypełnienia rysunku.
Składnia JavaScript: | kontekst .fillRect( 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