Canvas lineCap 属性

定义和用法

lineCap 属性设置或返回线条末端线帽的样式。

注释:"round" 和 "square" 会使线条略微变长。

实例

绘制圆形的结束线帽:

Your browser does not support the canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();ctx.lineCap="round";ctx.moveTo(20,20);
ctx.lineTo(20,200);
ctx.stroke();

亲自试一试

语法

context.lineCap="butt|round|square";

属性值

描述
butt默认。向线条的每个末端添加平直的边缘。
round向线条的每个末端添加圆形线帽。
square向线条的每个末端添加正方形线帽。

技术细节

默认值:butt

浏览器支持

表中的数字注明了首个完全支持该属性的浏览器版本。

ChromeEdgeFirefoxSafariOpera
ChromeEdgeFirefoxSafariOpera
4.09.03.64.010.1

注释:Internet Explorer 8 以及更早的版本不支持 <canvas> 元素。