Fabric.js 是一個用於處理畫布的 JavaScript 庫。畫布 Itext 是用於創建 Itext 實例的 Fabric.js 類之一。畫布 Itext 表示 Itext 是可移動的,可以根據需要進行拉伸。在本文中,我們將使用 strokeLineCap 屬性來設置或不設置筆劃線帽。此參數的可接受值為 ‘butt’、'round' 和 ‘square’。
首先導入 Fabric.js 庫。導入庫後,在 body 標簽中創建一個包含 Itext 的畫布塊。之後,初始化 Fabric.js 提供的 Canvas 和 Itext 類的實例,並使用 strokeLineCap 屬性。
用法:
fabric.Itext(Itext, { strokeLineCap:string });
參數:該函數采用上述和以下描述的單個參數:
- strokeLineCap:此參數采用指定是否設置筆劃線上限的字符串值。此參數的值可以是 ‘butt’、'round' 或 ‘square’ 之一。
例:本示例使用 Fabric.js 設置畫布 Itext 的 strokeLineCap 屬性。
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 | Itext strokeLineCap Property
</b>
</div>
<div style="text-align:center;">
<canvas id="canvas"
width="400" height="200"
style="border:1px solid green;">
</canvas>
</div>
<script>
var canvas = new fabric.Canvas("canvas");
var geek = new fabric.IText('GeeksforGeeks', {
fill:"",
stroke:"green",
// Specify the type of stroke line cap
strokeLineCap:"square"
});
canvas.add(geek);
canvas.centerObject(geek);
</script>
</body>
</html>
輸出:
相關用法
- Fabric.js Polygon strokeLineCap屬性用法及代碼示例
- Fabric.js Textbox strokeLineCap屬性用法及代碼示例
- Fabric.js Polyline strokeLineCap屬性用法及代碼示例
- Fabric.js Path strokeLineCap用法及代碼示例
- Fabric.js Group strokeLineCap屬性用法及代碼示例
- Fabric.js Text strokeLineCap屬性用法及代碼示例
- Fabric.js Itext transparentCorners屬性用法及代碼示例
- Fabric.js Itext borderOpacityWhenMoving屬性用法及代碼示例
- Fabric.js Itext borderDashArray屬性用法及代碼示例
- Fabric.js Itext cornerSize屬性用法及代碼示例
- Fabric.js Itext centeredRotation屬性用法及代碼示例
- Fabric.js Itext angle屬性用法及代碼示例
- Fabric.js Itext borderColor屬性用法及代碼示例
- Fabric.js Itext cornerStyle屬性用法及代碼示例
- Fabric.js Itext lockMovementX屬性用法及代碼示例
- Fabric.js Itext hoverCursor屬性用法及代碼示例
- Fabric.js Itext lockRotation屬性用法及代碼示例
- Fabric.js Itext lockMovementY屬性用法及代碼示例
- Fabric.js Itext fontStyle屬性用法及代碼示例
- Fabric.js Itext hasBorders屬性用法及代碼示例
- Fabric.js Itext opacity屬性用法及代碼示例
- Fabric.js Itext objectCaching屬性用法及代碼示例
- Fabric.js Itext flipX屬性用法及代碼示例
- Fabric.js Itext underline屬性用法及代碼示例
注:本文由純淨天空篩選整理自dheerchanana08大神的英文原創作品 Fabric.js Itext strokeLineCap Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。