Latest web development tutorials

HTML canvas lineCap 屬性

HTML canvas 參考手冊 HTML canvas參考手冊

實例

繪製圓形的結束線帽:

您的瀏覽器不支持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();

嘗試一下»

瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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 參考手冊 HTML canvas參考手冊