ข้อมูลอ้างอิง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 canvas textBaseline Property

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

ตัวอย่าง

ลากเส้นสีแดงที่ y=100 แล้ววางแต่ละคำที่ y=100 ด้วยค่า textBaseline ที่แตกต่างกัน:

YourbrowserdoesnotsupporttheHTML5canvastag.

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

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:

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