HTML canvas lineCapProperty

HTML canvas 参考手册HTML canvas Reference Manual

Examples

Draw a round line cap at the end of the line:

Your browser does not support the 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 Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

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


Definition and Usage

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

Note:The "round" and "square" values make the line slightly longer.

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

Property Values

Value Description
butt Default. Adds a flat edge to each end of the line.
round Adds a round line cap to each end of the line.
square Adds a square line cap to each end of the line.


HTML canvas 参考手册HTML canvas Reference Manual Other Extensions