案例:html/html5 案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<canvas id="myCanvas" width="300" height="200" style="border:1px solid #d3d3d3;">
6
Your browser does not support the HTML5 canvas tag.
7
</canvas>
8
9
<script>
10
11
var c=document.getElementById("myCanvas");
12
var ctx=c.getContext("2d");
13
14
// Create a red line in position 150
15
ctx.strokeStyle="blue";
16
ctx.moveTo(150,20);
17
ctx.lineTo(150,170);
18
ctx.stroke();
19
20
ctx.font="15px Arial";    
21
22
// Show the different textAlign values
23
ctx.textAlign="start";      
24
ctx.fillText("textAlign=start",150,60);        
25
ctx.textAlign="end";      
26
ctx.fillText("textAlign=end",150,80);                  
27
ctx.textAlign="left";      
28
ctx.fillText("textAlign=left",150,100);
29
ctx.textAlign="center";     
30
ctx.fillText("textAlign=center",150,120);              
31
ctx.textAlign="right";      
32
ctx.fillText("textAlign=right",150,140);
33
34
</script>
35
36
</body>
37
</html>
38