Fabric.js ActiveSelection strokeLineCap 属性
Fabric.js 是一个用于处理画布的 JavaScript 库。画布 ActiveSelection 是 fabric.js 的其中一个类,用于创建 ActiveSelection 实例。画布 ActiveSelection 表示 ActiveSelection 可以移动并根据需要进行拉伸。本文将使用 strokeLineCap 属性。
方法: 首先导入 fabric.js 库。导入库后,在 body 标签中创建一个包含 ActiveSelection 的画布块。然后,通过使用 Fabric.JS 提供的 Canvas 和 ActiveSelection 类的实例来使用 strokeLineCap 属性。
语法:
fabric.ActiveSelection(ActiveSelection, {
strokeLineCap : string
});
参数: 此函数接受一个参数,如上所述并在下面描述。
- strokeLineCap: 此参数接受一个字符串值。
示例: 此示例使用 FabricJS 来设置画布活动选择上的 strokeLineCap 属性,如下示例所示。
<!DOCTYPE html>
<html>
<head>
<!-- FabricJS CDN -->
<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:400px;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<b>
Fabric.js | ActiveSelection strokeLineCap Property
</b>
</div>
<div style="text-align: center;">
<canvas id="canvas" width="500" height="500"
style="border:1px solid green;">
</canvas>
</div>
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20200327230544/g4gicon.png"
width="100" height="100"
id="my-image" style="display:none;">
<script>
var canvas = new fabric.Canvas("canvas");
// Initiate a Rect instance
var rectangle = new fabric.Rect({
width: 200,
height: 100,
});
canvas.add(rectangle);
var itext = new fabric.IText('GeeksforGeeks', {
});
canvas.add(itext);
canvas.centerObject(itext);
var select = new fabric
.ActiveSelection(canvas.getObjects(), {
stroke: 'red',
strokeLineCap: 'butt',
strokeWidth: 9
})
canvas.setActiveObject(select);
canvas.requestRenderAll();
canvas.centerObject(select);
</script>
</body>
</html>
输出:
极客教程