TUTORIAL标准、参考与速查FETCHED
HTML canvas lineCap 属性
HTML canvas lineCap 属性 HTML canvas 参考手册 实例 绘制圆形的结束线帽: 您的浏览器不支持 HTML5 canvas 标签。 var c=document.getElementById('myCanvas'); var canvOK=1; try {c.getContext('2d');} catch (er) {canvOK=0;} if (can..
更新于 2026/7/16
教程详情页默认 noindex。
HTML canvas lineCap 属性
实例
绘制圆形的结束线帽:
您的浏览器不支持 HTML5 canvas 标签。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();
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.lineCap="round";
ctx.moveTo(20,20);
ctx.lineTo(20,200);
ctx.stroke();
尝试一下 »
浏览器支持
![]()
![]()
![]()
![]()
![]()
Internet Explorer 9、Firefox、Opera、Chrome 和 Safari 支持 lineCap 属性。
注意:Internet Explorer 8 及之前的版本不支持 <canvas> 元素。
定义和用法
lineCap 属性设置或返回线条末端线帽的样式。
注意:"round" 和 "square" 值会使线条略微变长。
| 默认值: | butt |
|---|---|
| JavaScript 语法: | context.lineCap="butt|round|square"; |
属性值
| 值 | 描述 |
|---|---|
| butt | 默认。向线条的每个末端添加平直的边缘。 |
| round | 向线条的每个末端添加圆形线帽。 |
| square | 向线条的每个末端添加正方形线帽。 |
HTML canvas 参考手册