Płótno HTML Metoda clearRect()
Przykład
Wyczyść prostokąt w danym prostokącie:
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);
Obsługa przeglądarki
Liczby w tabeli określają pierwszą wersję przeglądarki, która w pełni obsługuje tę metodę.
Method | |||||
---|---|---|---|---|---|
clearRect() | Yes | 9.0 | Yes | Yes | Yes |
Definicja i użycie
Metoda clearRect() czyści określone piksele w danym prostokącie.
Składnia JavaScript: | kontekst .clearRect( x,y,szerokość,wysokość ); |
---|
Wartości parametrów
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 |
❮ Odniesienie do płótna HTML