在位置 150 创建一条红线。位置 150 是下面实例中定义的所有文本的锚点。请研究每种 textAlign 属性值的效果:
var c=document.getElementById(“myCanvas”);
var ctx=c.getContext(“2d”);
// Create a red line in position 150
ctx.strokeStyle=“red”;
ctx.moveTo(150,20);
ctx.lineTo(150,170);
ctx.stroke();
ctx.font=“15px Arial”;
// Show the different textAlign values
ctx.textAlign=“start”;
ctx.fillText(“textAlign=start”,150,60);
ctx.textAlign=“end”;
ctx.fillText(“textAlign=end”,150,80);
ctx.textAlign=“left”;
ctx.fillText(“textAlign=left”,150,100);
**
ctx.textAlign="center";
ctx.fillText("textAlign=center",150,120);//150为画布的中心线位置
**
ctx.textAlign=“right”;
ctx.fillText(“textAlign=right”,150,140);