简体   繁体   English

用fabric.js绘制一条虚线

[英]Drawing a dashed line with fabric.js

I'd like to draw a dashed line using fabric.js. 我想用fabric.js画一条虚线。 I've found Issue #603 on github that should implement this feature. 我在github上找到了应该实现此功能的问题#603。 However I didn't find any example code and can't get it to work with fabric.js 1.2.1. 但是我没有找到任何示例代码,也无法使用fabric.js 1.2.1。

Is it already part of fabric.js 1.2.1 or do I have to get it off github directly and build it myself? 它已经是fabric.js 1.2.1的一部分了,还是我必须直接从github上取下它并自己构建它? Could someone provide me with a simple example to get me started? 有人能给我一个简单的例子让我开始吗?

The property you're looking for is strokeDashArray which encodes the SVG attribute stroke-dasharray . 您正在寻找的属性是strokeDashArray ,它对SVG属性stroke-dasharray编码。 It expects an array that describes the pattern of dashes and gaps, see the linked page for more details. 它需要一个描述破折号和间隙模式的数组,有关详细信息,请参阅链接页面。

An example of usage may look like the following, which would create a dashed black line with equally spaced 5px fills: 使用示例可能如下所示,这将创建具有等间距5px填充的黑色虚线:

new fabric.Line([0, 20, 100, 20], {
    strokeDashArray: [5, 5],
    stroke: 'black'
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM