نص لوحة HTML
مثال
قم بإنشاء خط أحمر في الموضع 150. الموضع 150 هو نقطة الربط لكل النص المحدد في المثال أدناه. ادرس تأثير كل نص قيمة خاصية محاذاة:
جافا سكريبت:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
// Create a red line in position 150
ctx.strokeStyle = "red";
ctx.moveTo(150, 20);
ctx.lineTo(150, 170);
ctx.stroke();
ctx.font = "15px Arial";
// Show the different textAlign values
ctx.textAlign = "start";
ctx.fillText("textAlign=start", 150, 60);
ctx.textAlign = "end";
ctx.fillText("textAlign=end", 150, 80);
ctx.textAlign = "left";
ctx.fillText("textAlign=left", 150, 100);
ctx.textAlign = "center";
ctx.fillText("textAlign=center", 150, 120);
ctx.textAlign = "right";
ctx.fillText("textAlign=right", 150, 140);
دعم المتصفح
تحدد الأرقام الواردة في الجدول إصدار المتصفح الأول الذي يدعم الخاصية بالكامل.
Property | |||||
---|---|---|---|---|---|
textAlign | Yes | 9.0 | Yes | Yes | Yes |
التعريف والاستخدام
تقوم خاصية textAlign بتعيين أو إرجاع المحاذاة الحالية لمحتوى النص ، وفقًا لنقطة الارتساء.
عادةً ، يبدأ النص في الموضع المحدد ، ومع ذلك ، إذا قمت بتعيين textAlign = "right" ووضع النص في الموضع 150 ، فهذا يعني أن النص يجب أن ينتهي في الموضع 150.
تلميح: استخدم طريقة fillText () أو strokeText () لرسم النص ووضعه على اللوحة القماشية.
القيمة الافتراضية: | بداية |
---|---|
بناء جملة JavaScript: | السياق .textAlign = "مركز | نهاية | يسار | يمين | بداية" ؛ |
قيم الملكية
Values | Description | Play it |
---|---|---|
start | Default. The text starts at the specified position | |
end | The text ends at the specified position | |
center | The center of the text is placed at the specified position | |
left | The text starts at the specified position | |
right | The text ends at the specified position |
❮ مرجع قماش HTML