Proprietà HTML canvas textBaseline
Esempio
Disegna una linea rossa su y=100, quindi posiziona ogni parola su y=100 con diversi valori textBaseline:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
//Draw a red line at y = 100
ctx.strokeStyle = "red";
ctx.moveTo(5, 100);
ctx.lineTo(395, 100);
ctx.stroke();
ctx.font = "20px Arial"
//Place each word at y = 100 with different textBaseline values
ctx.textBaseline = "top";
ctx.fillText("Top", 5, 100);
ctx.textBaseline = "bottom";
ctx.fillText("Bottom", 50, 100);
ctx.textBaseline = "middle";
ctx.fillText("Middle", 120, 100);
ctx.textBaseline = "alphabetic";
ctx.fillText("Alphabetic", 190, 100);
ctx.textBaseline = "hanging";
ctx.fillText("Hanging", 290, 100);
Supporto del browser
I numeri nella tabella specificano la prima versione del browser che supporta completamente la proprietà.
Property | |||||
---|---|---|---|---|---|
textBaseline | Yes | 9.0 | Yes | Yes | Yes |
Nota: la proprietà textBaseline funziona in modo diverso nei diversi browser, specialmente quando si utilizza "hanging" o "ideographic".
Definizione e utilizzo
La proprietà textBaseline imposta o restituisce la linea di base del testo corrente utilizzata durante il disegno del testo.
L'illustrazione seguente mostra le varie linee di base supportate dall'attributo textBaseline:
Nota: i metodi fillText() e strokeText() utilizzeranno il valore textBaseline specificato durante il posizionamento del testo sull'area di disegno.
Valore di default: | alfabetico |
---|---|
sintassi JavaScript: | context .textBaseline="alfabetico|in alto|appeso|medio|ideografico|in basso"; |
Valori di proprietà
Values | Description | Play it |
---|---|---|
alphabetic | Default. The text baseline is the normal alphabetic baseline | |
top | The text baseline is the top of the em square | |
hanging | The text baseline is the hanging baseline | |
middle | The text baseline is the middle of the em square | |
ideographic | The text baseline is the ideographic baseline | |
bottom | The text baseline is the bottom of the bounding box |
❮ Riferimento tela HTML