案例:html/html5 案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<canvas id="myCanvas" width="300" height="150" 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
// 红色矩形
15
ctx.beginPath();
16
ctx.lineWidth="6";
17
ctx.strokeStyle="red";
18
ctx.rect(5,5,290,140);  
19
ctx.stroke();
20
21
// 绿色矩形
22
ctx.beginPath();
23
ctx.lineWidth="4";
24
ctx.strokeStyle="green";
25
ctx.rect(30,30,50,50);
26
ctx.stroke();
27
28
// 蓝色矩形
29
ctx.beginPath();
30
ctx.lineWidth="10";
31
ctx.strokeStyle="blue";
32
ctx.rect(50,50,150,80);
33
ctx.stroke();
34
</script> 
35
36
</body>
37
</html>
38