Returns or sets the text alignment value. See return value description below.
Property of apis/canvas/CanvasRenderingContext2Dapis/canvas/CanvasRenderingContext2D
Syntaxvar result = CanvasRenderingContext2D.textAlign;
CanvasRenderingContext2D.textAlign = value;
Return Value
Returns an object of type StringString
Must be one of the following:
<canvas id="myCanvas" width="300" height="150" style="border:1px solid blue;"></canvas>
<p>. . .</p>
<script>
var can=document.getElementById("myCanvas");
var ctxt=can.getContext("2d");
ctxt.strokeStyle="green";
ctxt.moveTo(150,0);
ctxt.lineTo(150,150);
ctxt.stroke();
ctxt.font="16px Arial";
ctxt.textAlign="start";
ctxt.fillText("START",150,40);
ctxt.textAlign="end";
ctxt.fillText("END",150,60);
ctxt.textAlign="left";
ctxt.fillText("LEFT",150,80);
ctxt.textAlign="right";
ctxt.fillText("RIGHT",150,100);
ctxt.textAlign="center";
ctxt.fillText("CENTER",150,120);
</script>
Notes
The exact alignment depends on whether the direction of HTMLCanvasElement is left-to-right (ltr) or right-to-left (rtl). The textBaseline value also determines the anchor point of the text.
Related specificationsMicrosoft Developer Network: Windows Internet Explorer API reference Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4