TextBaseline қасиеті
textBaseline қасиеті
fillText
әдісі немесе strokeText
әдісімен салынған мәтіндің тік орналасуын белгілейді.
Мүмән мәндердің бірін қабылдайды: top,
hanging, middle, alphabetic (әдепкі бойынша),
ideographic, bottom (мәндерді түсіну үшін
қараңыз: www.w3schools.com/tags/canvas_textbaseline.asp).
Синтаксис
контекст.textBaseline = мән;
Мысал
Мәтіндің тік орналасуын жоғарғы сызық бойынша белгілейік:
<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);
:
Мысал
Енді мәтіндің тік орналасуын төменгі сызық бойынша белгілейік:
<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);
: