คุณสมบัติ direction
คุณสมบัติ direction กำหนดทิศทาง
ของข้อความที่วาดด้วยวิธี fillText
หรือวิธี strokeText
รับค่าที่เป็นไปได้หนึ่งใน: ltr
(จากซ้ายไปขวา), rtl (จากขวาไปซ้าย), inherit
(สืบทอด) ค่าเริ่มต้นคือ
inherit (สำหรับภาษาอาหรับและภาษาฮิบรูจะได้
rtl เนื่องจากเขียนจากขวาไปซ้าย ส่วน
ภาษาอื่น ๆ ทั้งหมด - ltr)
ไวยากรณ์
context.direction = ltr หรือ rtl หรือ inherit;
ตัวอย่าง
ลองเขียนข้อความและกำหนด
ทิศทางที่แตกต่างกันด้วย
คุณสมบัติ direction:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
ctx.font = "16px arial";
ctx.fillText("text1", 150, 50);
ctx.direction = "rtl";
ctx.fillText("text1", 50, 120);
:
ดูเพิ่มเติม
-
คุณสมบัติ
textBaseline,
ซึ่งจัดแนวข้อความในแนวตั้ง -
คุณสมบัติ
textAlign,
ซึ่งจัดแนวข้อความในแนวนอน