TextBaseline häsiýeti

textBaseline häsiýeti, fillText metodu ýa-da strokeText metodu arkaly çekilen tekst üçin düýş taýdan deňlemäni düzýär. Mümkin bahalardan birini alýar: top, hanging, middle, alphabetic (deslapky ýagdaýda), ideographic, bottom (bahalary düşünmek üçin www.w3schools.com/tags/canvas_textbaseline.asp sahypasyna serediň).

Sintaksis

javascriptkontekst.textBaseline = baha;

Mysal

Geliň, tekst üçin ýokarky çyzyk boýunça düýş taýdan deňleme düzeliň:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptconst 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('tekst', 80, 100);

Результат:

Mysal

Indi bolsa, geliň, tekst üçin aşaky çyzyk boýunça düýş taýdan deňleme düzeliň:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptconst 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('tekst', 80, 100); 

Результат:

Şeýle-de serediň

  • textAlign häsiýeti,
    teksti göni taýdan deňleýär
  • font häsiýeti,
    şriftiň ululygyny we görnüşini düzýär