ข้อมูลอ้างอิงHTML

HTML โดยตัวอักษร HTML ตามหมวดหมู่ รองรับ HTML Browser แอตทริบิวต์ HTML HTML Global Attributes เหตุการณ์ HTML HTML สี HTML Canvas HTML เสียง/วิดีโอ ชุดอักขระ HTML HTML Doctypes การเข้ารหัส URL HTML รหัสภาษา HTML รหัสประเทศ HTML ข้อความ HTTP วิธี HTTP ตัวแปลง PX เป็น EM แป้นพิมพ์ลัด


แก้ไขผ้าใบ HTML ()วิธีการ

❮ อ้างอิงผ้าใบ HTML

ตัวอย่าง

วาดรูปสี่เหลี่ยมผืนผ้า 150*100 พิกเซล:

YourbrowserdoesnotsupporttheHTML5canvastag.

จาวาสคริปต์:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(20, 20, 150, 100);
ctx.stroke();

รองรับเบราว์เซอร์

ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่รองรับวิธีการนี้อย่างเต็มที่

Method
rect() Yes 9.0 Yes Yes Yes

ความหมายและการใช้งาน

วิธี rect() สร้างสี่เหลี่ยม

เคล็ดลับ:ใช้วิธีstroke()หรือ fill()เพื่อวาดรูปสี่เหลี่ยมผืนผ้าบนผืนผ้าใบ

ไวยากรณ์ JavaScript: บริบท .rect( x,y,ความกว้าง,ความสูง );

ค่าพารามิเตอร์

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

ตัวอย่างเพิ่มเติม

ตัวอย่าง

สร้างสี่เหลี่ยมสามรูปโดยใช้วิธี rect():

เบราว์เซอร์ของคุณไม่สนับสนุนผ้าใบ

จาวาสคริปต์:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");

// Red rectangle
ctx.beginPath();
ctx.lineWidth = "6";
ctx.strokeStyle = "red";
ctx.rect(5, 5, 290, 140);
ctx.stroke();

// Green rectangle
ctx.beginPath();
ctx.lineWidth = "4";
ctx.strokeStyle = "green";
ctx.rect(30, 30, 50, 50);
ctx.stroke();

// Blue rectangle
ctx.beginPath();
ctx.lineWidth = "10";
ctx.strokeStyle = "blue";
ctx.rect(50, 50, 150, 80);
ctx.stroke();


❮ อ้างอิงผ้าใบ HTML