案例:html/html5 案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<p>三种不同的线帽:</p>
6
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
7
Your browser does not support the HTML5 canvas tag.
8
</canvas>
9
10
<script>
11
12
var c=document.getElementById("myCanvas");
13
var ctx=c.getContext("2d");
14
15
ctx.beginPath();
16
ctx.lineWidth=10;
17
ctx.lineCap="butt";
18
ctx.moveTo(20,20);
19
ctx.lineTo(200,20);
20
ctx.stroke();
21
22
ctx.beginPath();
23
ctx.lineCap="round";
24
ctx.moveTo(20,40);
25
ctx.lineTo(200,40);
26
ctx.stroke();
27
28
ctx.beginPath();
29
ctx.lineCap="square";
30
ctx.moveTo(20,60);
31
ctx.lineTo(200,60);
32
ctx.stroke();
33
34
</script>
35
36
</body>
37
</html>
38