畫布折線表示折線是可移動的,可以根據需要進行拉伸。此外,當涉及初始筆劃顏色,形狀,填充顏色或筆劃寬度時,可以定製折線。
為了設置畫布Polyline的邊框,使用了名為FabricJS的JavaScript庫。導入庫後,我們將在body標記中創建一個包含多段線的畫布塊。此後,我們將初始化由FabricJS提供的Canvas和Polyline實例,並使用hasBorders屬性設置畫布Polyline的邊框,並按照以下示例中的說明在Canvas上渲染Polyline。
用法:
fabric.Polyline([
{ x:pixel, y:pixel },
{ x:pixel, y:pixel },
{ x:pixel, y:pixel},
{ x:pixel, y:pixel},
{ x:pixel, y:pixel }],
{ hasBorders:boolean }
);
參數:該屬性接受上述和以下描述的單個參數:
- hasBorders:它指定是否使邊框可見。
注意:尺寸像素必須創建一條折線。
下麵的示例說明了Fabric.js中的hasBorders屬性:
例:
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:600px;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<b>
Fabric.js | Polyline hasBorders Property
</b>
</div>
<canvas id="canvas"
width="600"
height="200"
style="border:1px solid #000000;">
</canvas>
<script>
// Initiate a Canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate a polyline instance
var polyline = new fabric.Polyline([
{x:200, y:10 },
{x:250, y:50 },
{x:250, y:180 },
{x:150, y:180 },
{x:150, y:50 },
{x:200, y:10 }],
{
stroke:'green',
strokeWidth:3,
cornerStyle:'circle',
excludeFromExport:false,
hasBorders:false
});
// Render the polyline in canvas
canvas.add(polyline);
</script>
</body>
</html>
輸出:
範例2:在此示例中,hasBorders屬性設置為true。
Java腳本
<!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:600px;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<b>
Fabric.js | Polyline hasBorders Property
</b>
</div>
<canvas id="canvas"
width="600"
height="200"
style="border:1px solid #000000;">
</canvas>
<script>
// Initiate a Canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate a polyline instance
var polyline = new fabric.Polyline([
{x:200, y:10 },
{x:250, y:50 },
{x:250, y:180 },
{x:150, y:180 },
{x:150, y:50 },
{x:200, y:10 }],
{
stroke:'green',
strokeWidth:3,
cornerStyle:'circle',
excludeFromExport:false,
hasBorders:true
});
// Render the polyline in canvas
canvas.add(polyline);
</script>
</body>
</html>
輸出:
相關用法
- Fabric.js Triangle hasBorders屬性用法及代碼示例
- Fabric.js Ellipse hasBorders屬性用法及代碼示例
- Fabric.js Rect hasBorders屬性用法及代碼示例
- Fabric.js Image hasBorders屬性用法及代碼示例
- Fabric.js Polygon hasBorders屬性用法及代碼示例
- Fabric.js Textbox hasBorders屬性用法及代碼示例
- Fabric.js line hasBorders屬性用法及代碼示例
- Fabric.js Path hasBorders屬性用法及代碼示例
- Fabric.js Itext hasBorders屬性用法及代碼示例
- Fabric.js Group hasBorders屬性用法及代碼示例
- Fabric.js Polyline absolutePositioned屬性用法及代碼示例
- Fabric.js Polyline lockScalingX屬性用法及代碼示例
- Fabric.js Polyline lockScalingFlip屬性用法及代碼示例
- Fabric.js Polyline flipY屬性用法及代碼示例
- Fabric.js Polyline fill屬性用法及代碼示例
- Fabric.js Polyline skewY屬性用法及代碼示例
- Fabric.js Polyline lockScalingY屬性用法及代碼示例
- Fabric.js Polyline lockSkewingY屬性用法及代碼示例
- Fabric.js Polyline stroke屬性用法及代碼示例
- Fabric.js Polyline borderDashArray屬性用法及代碼示例
- Fabric.js Polyline angle屬性用法及代碼示例
- Fabric.js Polyline backgroundColor屬性用法及代碼示例
- Fabric.js Polyline borderColor屬性用法及代碼示例
- Fabric.js Polyline cornerStrokeColor屬性用法及代碼示例
注:本文由純淨天空篩選整理自skyridetim大神的英文原創作品 Fabric.js Polyline hasBorders Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。