Stroke() | HTML<canvas>方法
定义与用法
stroke() 方法会实际地绘制出通过 moveTo() 和 lineTo() 方法定义的路径。默认颜色是黑色。
提示:请使用 strokeStyle 属性来绘制另一种颜色/渐变。
语法格式
context.stroke();
示例代码
<script>
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();
</script>
效果展示:
浏览器支持
方法 | |||||
---|---|---|---|---|---|
Stroke() | Yes | Yes | Yes | Yes | Yes |
Internet Explorer 9、Firefox、Opera、Chrome 和 Safari 支持 stroke() 方法。
提示:Internet Explorer 8 及之前的版本不支持 <canvas> 元素。