在本文中,我们将看到如何使用FabricJS将笔划偏移添加到Polyline画布。画布意味着Polyline可以移动,旋转,调整大小并可以拉伸。但是在本文中,我们将添加笔触偏移量。此外,折线本身无法像文本框一样进行编辑。
为了使其成为可能,我们将使用一个名为FabricJS的JavaScript库。使用CDN导入库后,我们将在body标签中创建一个画布块,其中包含我们的折线。此后,我们将初始化FabricJS提供的Canvas和Polyline实例,并使用stroke属性创建一个笔触,然后进一步使用strokeDashOffset属性添加笔触偏移量,并在多边形上渲染Canvas,如下面的示例所示。
用法:
var polyline = new fabric.Polyline(Points, { strokeDashOffset:number });
参数:该属性接受上述和以下描述的单个参数:
- strokeDashOffset:此参数定义笔划的偏移量。
下面的示例说明了Fabric.js中的strokeDashOffset属性:
例:
HTML
<!DOCTYPE html>
<html>
<head>
<!-- Loading the FabricJS library -->
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">
</script>
</head>
<body>
<div style="text-align:center;width:600px;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<b>
Fabric.js | Polyline strokeDashOffset Property
</b>
</div>
<canvas id="canvas" width="600"
height="200" style="border:1px solid #000000;">
</canvas>
<script>
// Initiate a Canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate a polyline instance
var polyline = new fabric.Polyline([
{ x:200, y:10 },{x:250,y:50},
{ x:250, y:180},{x:150,y:180},
{ x:150, y:50 },{ x:200,y:10 }],
{
stroke:'green',
strokeWidth:3,
cornerStyle:'circle',
strokeDashOffset:10,
});
// Render the polyline in canvas
canvas.add(polyline);
</script>
</body>
</html>
输出:
相关用法
- Fabric.js Text strokeDashOffset属性用法及代码示例
- Fabric.js Triangle strokeDashOffset属性用法及代码示例
- Fabric.js Textbox strokeDashOffset属性用法及代码示例
- Fabric.js Polygon strokeDashOffset属性用法及代码示例
- Fabric.js Circle strokeDashOffset属性用法及代码示例
- Fabric.js Ellipse strokeDashOffset属性用法及代码示例
- Fabric.js Path strokeDashOffset属性用法及代码示例
- Fabric.js Image strokeDashOffset属性用法及代码示例
- Fabric.js Group strokeDashOffset属性用法及代码示例
- Fabric.js Polyline absolutePositioned属性用法及代码示例
- Fabric.js Polyline lockScalingX属性用法及代码示例
- Fabric.js Polyline lockScalingFlip属性用法及代码示例
- Fabric.js Polyline flipY属性用法及代码示例
- Fabric.js Polyline fill属性用法及代码示例
- Fabric.js Polyline skewY属性用法及代码示例
- Fabric.js Polyline lockScalingY属性用法及代码示例
- Fabric.js Polyline lockSkewingY属性用法及代码示例
- Fabric.js Polyline stroke属性用法及代码示例
- Fabric.js Polyline borderDashArray属性用法及代码示例
- Fabric.js Polyline angle属性用法及代码示例
- Fabric.js Polyline backgroundColor属性用法及代码示例
- Fabric.js Polyline borderColor属性用法及代码示例
- Fabric.js Polyline cornerStrokeColor属性用法及代码示例
- Fabric.js Polyline cornerStyle属性用法及代码示例
注:本文由纯净天空筛选整理自skyridetim大神的英文原创作品 Fabric.js Polyline strokeDashOffset Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。