Xüsusiyyət textBaseline
Xüsusiyyət textBaseline,
fillText metodu və ya
strokeText metodu ilə
çəkilmiş mətnin şaquli düzləndirilməsini təyin edir.
Mümkün dəyərlərdən birini qəbul edir: top,
hanging, middle, alphabetic (standart olaraq),
ideographic, bottom (dəyərlərin başa düşülməsi üçün
bax: www.w3schools.com/tags/canvas_textbaseline.asp).
Sintaksis
kontekst.textBaseline = deyer;
Nümunə
Gəlin mətnə üst xətt üzrə şaquli düzləndirmə təyin edək:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.strokeStyle = 'red';
ctx.moveTo(0, 100);
ctx.lineTo(400, 100);
ctx.stroke();
ctx.font="14px Arial";
ctx.textBaseline = 'top';
ctx.fillText('text', 80, 100);
:
Nümunə
İndi isə gəlin mətnə alt xətt üzrə şaquli düzləndirmə təyin edək:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.strokeStyle = 'red';
ctx.moveTo(0, 100);
ctx.lineTo(400, 100);
ctx.stroke();
ctx.font="14px Arial";
ctx.textBaseline="bottom";
ctx.fillText('text', 80, 100);
: