javascript - Fabric.js指定lineCap样式

标签 javascript fabricjs

html5 canvas中可以指定lineCap style用于行尾。

例如:

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);

可能的选项有:对接(默认)、圆形、方形

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

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?
    }
);

最佳答案

我找到了答案

将其发布在此处,因为从 Fabric.js 文档中看不出来:

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

关于javascript - Fabric.js指定lineCap样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42053827/

相关文章:

c# - 通过数组作为 $ajax 参数 MVC

javascript - 如何在 WebView 中启用 javascript

canvas - 如何在发送到服务器之前减小 Canvas 图像的大小

javascript - 使用 Fabric.js 缩放 Canvas 时实现图像像素完美缩放

svg - 如何使用大量对象提高 canvas fabric.js 性能

javascript - 想了解iframe突破代码

javascript - 更新 .Net Codebehind 中的 javascript 变量

javascript - 两个脚本将不同的监听器添加到同一元素

javascript - canvas.clear() 上的 Canvas 变得不完全清晰

javascript - 在 FabricJS 中绘制后无法选择对象