HTML canvas textAlign Özellik

❮ HTML Kanvas Referansı

Örnek

150 konumunda kırmızı bir çizgi oluşturun. 150. konum, aşağıdaki örnekte tanımlanan tüm metinler için bağlantı noktasıdır. Her textAlign özellik değerinin etkisini inceleyin:

TarayıcınızHTML5tuval etiketini desteklemiyor.

JavaScript:

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);

Tarayıcı Desteği

Tablodaki sayılar, özelliği tam olarak destekleyen ilk tarayıcı sürümünü belirtir.

Property
textAlign Yes 9.0 Yes Yes Yes

Tanım ve Kullanım

textAlign özelliği, bağlantı noktasına göre metin içeriği için geçerli hizalamayı ayarlar veya döndürür.

Normalde, metin belirtilen konumda BAŞLAYACAKTIR , ancak textAlign="right" öğesini ayarlarsanız ve metni 150 konumuna yerleştirirseniz, bu, metnin 150 konumunda BİTMESİ gerektiği anlamına gelir .

İpucu: Metni tuval üzerine çizmek ve konumlandırmak için fillText () veya StroText() yöntemini kullanın.

Varsayılan değer: Başlat
JavaScript sözdizimi: bağlam .textAlign="merkez|son|sol|sağ|başlangıç";

Mülk değerleri

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 Kanvas Referansı