stroke()
实例
绘制一条路径,形状是红色的字母 L:
JavaScript:
var c=document.getelementbyid("myCanvas");
var ctx=c.getcontext("2d");
ctx.beginpath();
ctx.moveto(20,20);
ctx.lineto(20,100);
ctx.lineto(70,100);
ctx.strokestyle="red";
ctx.stroke();浏览器支持
![]() | ![]() | ![]() | ![]() | ![]() |
| Internet Explorer 9、Firefox、Opera、Chrome 和 Safari 支持 stroke()方法。 | ||||
| 注意:Internet Explorer 8 及之前的版本不支持<canvas>元素。 | ||||
定义和用法
stroke()方法会实际地绘制出通过 moveTo()和 lineTo()方法定义的路径。默认颜色是黑色。
提示:请使用strokeStyle属性来绘制另一种颜色/渐变。
| JavaScript 语法: | context.stroke(); |
|---|





