HTML canvas textBaseline Property
ตัวอย่าง
ลากเส้นสีแดงที่ y=100 แล้ววางแต่ละคำที่ y=100 ด้วยค่า textBaseline ที่แตกต่างกัน:
จาวาสคริปต์:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
//Draw a red line at y = 100
ctx.strokeStyle = "red";
ctx.moveTo(5, 100);
ctx.lineTo(395, 100);
ctx.stroke();
ctx.font = "20px Arial"
//Place each word at y = 100 with different textBaseline values
ctx.textBaseline = "top";
ctx.fillText("Top", 5, 100);
ctx.textBaseline = "bottom";
ctx.fillText("Bottom", 50, 100);
ctx.textBaseline = "middle";
ctx.fillText("Middle", 120, 100);
ctx.textBaseline = "alphabetic";
ctx.fillText("Alphabetic", 190, 100);
ctx.textBaseline = "hanging";
ctx.fillText("Hanging", 290, 100);
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์
Property | |||||
---|---|---|---|---|---|
textBaseline | Yes | 9.0 | Yes | Yes | Yes |
หมายเหตุ:คุณสมบัติ textBaseline ทำงานแตกต่างกันในเบราว์เซอร์ที่แตกต่างกัน โดยเฉพาะอย่างยิ่งเมื่อใช้ "แฮงก์" หรือ "เชิงอุดมคติ"
ความหมายและการใช้งาน
คุณสมบัติ textBaseline ตั้งค่าหรือส่งคืนบรรทัดฐานของข้อความปัจจุบันที่ใช้เมื่อวาดข้อความ
ภาพประกอบด้านล่างแสดงเส้นฐานต่างๆ ที่สนับสนุนโดยแอตทริบิวต์ textBaseline:
หมายเหตุ: เมธอด fillText ()และ strokeText()จะใช้ค่า textBaseline ที่ระบุเมื่อวางตำแหน่งข้อความบนผืนผ้าใบ
ค่าเริ่มต้น: | ตัวอักษร |
---|---|
ไวยากรณ์ JavaScript: | บริบท .textBaseline="alphabetic|top|hanging|middle|ideographic|bottom"; |
มูลค่าทรัพย์สิน
Values | Description | Play it |
---|---|---|
alphabetic | Default. The text baseline is the normal alphabetic baseline | |
top | The text baseline is the top of the em square | |
hanging | The text baseline is the hanging baseline | |
middle | The text baseline is the middle of the em square | |
ideographic | The text baseline is the ideographic baseline | |
bottom | The text baseline is the bottom of the bounding box |
❮ อ้างอิงผ้าใบ HTML