ใช้วิธีการ strokeRect() ของผ้าใบ HTML เพื่อสร้างสี่เหลี่ยมผืนผ้าบนหน้าเว็บ
ต่อไปนี้เป็นไวยากรณ์ -
context.strokeRect(p,q,width,height);
ข้างบน
- p − พิกัด x ของมุมบนซ้ายของสี่เหลี่ยม
- q − พิกัด y ของมุมบนซ้ายของสี่เหลี่ยม
- ความกว้าง − ความกว้างของสี่เหลี่ยม
- ความสูง − ความสูงของสี่เหลี่ยมผืนผ้า
ให้เรามาดูตัวอย่างการใช้คุณสมบัติ strokeStyle ของ canvas -
ตัวอย่าง
<!DOCTYPE html>
<html>
<body>
<canvas id="newCanvas" width="550" height="400" style="border −2px solid orange;"></canvas>
<script>
var c = document.getElementById("newCanvas");
var ctx = c.getContext("2d");
ctx.strokeRect(120, 120, 220, 120);
</script>
</body>
</html> ผลลัพธ์
