在本文中,我們將看到如何使用Fabric.js設置路徑的頂部。 Fabric.js中的Path是可移動的,可以根據需要進行拉伸。此外,當涉及初始筆觸顏色,高度,寬度,填充顏色或筆劃寬度時,可以自定義路徑。
方法:為了使之成為可能,我們將使用一個名為Fabric.js的JavaScript庫。導入庫後,我們將在包含路徑的body標簽中創建一個canvas塊。此後,我們將初始化Fabric.js提供的canvas和path實例,以使用top屬性將畫布路徑相對於top定位。
用法:
fabric.Path('path', { top:Number; });
參數:該函數接受如上所述和以下描述的單個參數。
- top:它指定相對於頂部的位置畫布路徑。
下麵的示例說明JavaScript中Fabric.js Path top屬性的使用。
例:
HTML
<!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 | Path top Property
</b>
</div>
<div style="text-align:center;">
<canvas id="canvas" width="400" height="200"
style="border:1px solid green;">
</canvas>
</div>
<script>
// Initiate a Canvas instance
var canvas = new fabric.Canvas("canvas");
var geek = new fabric.Path('M 0 0 L 100 100 L 0 100 z', {
fill:'green',
top:85
});
canvas.add(geek);
</script>
</body>
</html>
輸出:
相關用法
- CSS border-top-width用法及代碼示例
- CSS margin-top用法及代碼示例
- CSS border-top-right-radius屬性用法及代碼示例
- HTML Window top()用法及代碼示例
- CSS border-top用法及代碼示例
- CSS border-top-color用法及代碼示例
- CSS top屬性用法及代碼示例
- CSS padding-top用法及代碼示例
- HTML Style top用法及代碼示例
- CSS border-top-style用法及代碼示例
- CSS border-top-left-radius屬性用法及代碼示例
- HTML DOMRect top用法及代碼示例
- Fabric.js Ellipse top屬性用法及代碼示例
- Fabric.js Rect top屬性用法及代碼示例
- CSS scroll-margin-top屬性用法及代碼示例
- Fabric.js Triangle top屬性用法及代碼示例
- Fabric.js Textbox top屬性用法及代碼示例
- Fabric.js line top屬性用法及代碼示例
- Fabric.js Polyline top屬性用法及代碼示例
- Fabric.js Polygon top屬性用法及代碼示例
- Fabric.js Image top屬性用法及代碼示例
- Fabric.js Group top屬性用法及代碼示例
- node.js path.delimiter用法及代碼示例
注:本文由純淨天空篩選整理自thacker_shahid大神的英文原創作品 Fabric.js Path top Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。