案例:html/html5 案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<canvas id="myCanvas" width="400" height="200" style="border:1px solid #d3d3d3;">
6
Your browser does not support the HTML5 canvas tag.</canvas>
7
8
<script>
9
10
var c=document.getElementById("myCanvas");
11
var ctx=c.getContext("2d");
12
13
//Draw a red line at y=100
14
ctx.strokeStyle="blue";
15
ctx.moveTo(5,100);
16
ctx.lineTo(395,100);
17
ctx.stroke();
18
19
ctx.font="20px Arial"
20
21
//Place each word at y=100 with different textBaseline values
22
ctx.textBaseline="top"; 
23
ctx.fillText("Top",5,100); 
24
ctx.textBaseline="bottom"; 
25
ctx.fillText("Bottom",50,100); 
26
ctx.textBaseline="middle"; 
27
ctx.fillText("Middle",120,100); 
28
ctx.textBaseline="alphabetic"; 
29
ctx.fillText("Alphabetic",190,100); 
30
ctx.textBaseline="hanging"; 
31
ctx.fillText("Hanging",290,100); 
32
33
</script>
34
35
</body>
36
</html>
37