案例: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"; 

 运行结果 
 北美留学生论坛