วิธีการ fill() ในผ้าใบ HTML ใช้เพื่อเติมเส้นทางการวาดปัจจุบัน ค่าเริ่มต้นคือสีดำ
ต่อไปนี้เป็นไวยากรณ์−
ctx.fill();
ให้เราดูตัวอย่างการใช้เมธอด fill() ของ canvas -
ตัวอย่าง
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="450" height="250" style="border:2px solid blue;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(50, 60, 300, 200);
ctx.fillStyle = "green";
ctx.fill();
</script>
</body>
</html> ผลลัพธ์
