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