在本文中,我們將看到如何使用 Fabric.js 更改文本畫布的居中縮放。畫布意味著書寫的文本是可移動、可旋轉、可調整大小和可拉伸的。此外,文本本身不能像文本框一樣編輯。
為此,我們將使用一個名為 Fabric.js 的 JavaScript 庫。使用 CDN 導入庫後,我們將在 body 標簽中創建一個包含文本的畫布塊。之後,我們將初始化 FabricJS 提供的 Canvas 和 Text 的實例,並使用 centralScaling 屬性啟用畫布文本的居中縮放。
用法:
fabric.Text(text, centeredScaling:Boolean );
參數:此屬性接受如上所述和以下所述的一個參數:
- centeredScaling:此參數定義啟用還是禁用居中縮放。
下麵的示例說明了在 Fabric.js 中使用 centricScaling 屬性:
例:
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:400px;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<b>
Fabric.js | Text centeredScaling Property
</b>
</div>
<div style="text-align:center;">
<canvas id="canvas" width="400" height="200"
style="border:1px solid green;">
</canvas>
</div>
<script>
// Create a new instace of Canvas
var canvas = new fabric.Canvas("canvas");
// Create a new Text instance
var geek = new fabric.Text('GeeksforGeeks', {
centeredScaling:true
});
// Render the text on Canvas
canvas.add(geek);
canvas.centerObject(geek);
</script>
</body>
</html>
輸出:
相關用法
- Fabric.js Ellipse centeredScaling屬性用法及代碼示例
- Fabric.js Rect centeredScaling屬性用法及代碼示例
- Fabric.js Triangle centeredScaling屬性用法及代碼示例
- Fabric.js Image centeredScaling屬性用法及代碼示例
- Fabric.js Polygon centeredScaling屬性用法及代碼示例
- Fabric.js Textbox centeredScaling屬性用法及代碼示例
- Fabric.js line centeredScaling屬性用法及代碼示例
- Fabric.js Polyline centeredScaling屬性用法及代碼示例
- Fabric.js Path centeredScaling屬性用法及代碼示例
- Fabric.js Circle centeredScaling屬性用法及代碼示例
- Fabric.js Group centeredScaling屬性用法及代碼示例
- Fabric.js Itext centeredScaling屬性用法及代碼示例
- CSS text-align用法及代碼示例
- Fabric.js Text objectCaching屬性用法及代碼示例
- CSS text-decoration用法及代碼示例
- CSS text-decoration-color用法及代碼示例
- CSS text-decoration-line用法及代碼示例
- CSS text-justify用法及代碼示例
注:本文由純淨天空篩選整理自thacker_shahid大神的英文原創作品 Fabric.js Text centeredScaling Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。