HTML 캔버스 clearRect() 메서드
예시
주어진 사각형 내에서 사각형 지우기:
자바스크립트:
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);
브라우저 지원
표의 숫자는 이 방법을 완전히 지원하는 첫 번째 브라우저 버전을 지정합니다.
Method | |||||
---|---|---|---|---|---|
clearRect() | Yes | 9.0 | Yes | Yes | Yes |
정의 및 사용
clearRect() 메서드는 주어진 사각형 내에서 지정된 픽셀을 지웁니다.
자바스크립트 구문: | 컨텍스트 .clearRect( x, y, 너비, 높이 ); |
---|
매개변수 값
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 |
❮ HTML 캔버스 참조