HTML canvas strokeRect() Method
Paglilinaw at Paggamit
strokeRect()
Paraan na maitatala ang rectangle (walang kulay). Ang default na kulay ng touch ay ang puti.
Mga tip:Gumamit ng strokeStyle Gagamitin ang mga attribute upang itakda ang kulay ng touch, gradient o pattern.
Sample
Ilikha ng 150*100 pixel na parihaba ng rectangle:
JavaScript:
var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.strokeRect(20,20,150,100);
รูปแบบ
context.strokeRect(x,y,width,height);
ค่าตัวแปร
ตัวแปร | การอธิบาย |
---|---|
x | ตำแหน่ง x ของมุมบนซ้ายของรูปสี่เหลี่ยมผืนผ้า |
y | ตำแหน่ง y ของมุมบนซ้ายของรูปสี่เหลี่ยมผืนผ้า |
width | ความกว้างของรูปสี่เหลี่ยมผืนผ้า ในหน่วยพิกเซล |
height | ความสูงของรูปสี่เหลี่ยมผืนผ้า ในหน่วยพิกเซล |
การสนับสนุนโดยบราวเซอร์
ตัวเลขในตารางนี้ระบุว่าเวอร์ชั่นบราวเซอร์แรกที่สนับสนุนคุณสมบัตินี้
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
หมายเหตุ:Internet Explorer 8 และเวอร์ชั่นที่เก่ากว่าไม่สนับสนุนสิ่งที่ชื่อว่า <canvas> อิเล็กทรอนิกส์