Latest web development tutorials

HTML canvas lineCap property

HTML canvas Reference Manual HTML canvas Reference Manual

Examples

Draw the circle line of the end cap:

Your browser does not support HTML5 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();

try it"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9, Firefox, Opera, Chrome and Safari support lineCap property.

Note: 8 and earlier versions of Internet Explorer do not support the <canvas> element.


Definition and Usage

lineCap property sets or returns the line end of the line cap style.

Note: "round" and "square" value makes the lines a little longer.

Defaults: butt
JavaScript syntax: context .lineCap = "butt | round |square";

Property Value

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


HTML canvas Reference Manual HTML canvas Reference Manual