ผ้าใบ 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() วิธีการล้างพิกเซลที่ระบุภายในสี่เหลี่ยมที่กำหนด
ไวยากรณ์ JavaScript: | บริบท .clearRect ( x,y,width,height ); |
---|
ค่าพารามิเตอร์
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