Fabric.js指定lineCap样式

时间:2017-02-05 15:32:45

标签: javascript fabricjs

html5 canvas中,可以为行结束指定lineCap style

E.g:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.lineCap="round";    // <-- here lineCap is specified
ctx.moveTo(20,20);
ctx.lineTo(200,20);

可能的选项是:butt (Default), round, square

我的问题是:
在使用fabric.js创建lineCap时如何指定Line样式?

var line = new fabric.Line(
    [0, 100, 200, 100],
    {
        strokeWidth: 5
        // I presume some option should be specified here, but how is it should be called?
    }
);

1 个答案:

答案 0 :(得分:1)

我找到了答案

在此处发布,因为在fa​​bric.js文档中并不明显:

var line = new fabric.Line(
    [0, 100, 200, 100],
    {
        strokeWidth: 5,
        strokeLineCap: "round"   // <-- this makes 'round' line ends style
    }
);