在本文中,我們將看到如何使用Fabric.js設置畫布組的objectCaching。 Fabric.js中的組是可移動的,可以根據需要進行拉伸。此外,可以在初始筆劃顏色,高度,寬度,填充顏色或筆劃寬度方麵自定義組。
為了使之成為可能,我們將使用一個名為Fabric.js的JavaScript庫。導入庫後,我們將在body標簽中創建一個畫布塊,其中將包含Group。之後,我們將初始化由Fabric.js提供的Canvas和Group的實例,並使用objectCaching屬性設置canvas Group的objectCaching。
用法:
fabric.Group([canvas1, canvas2], { objectCaching:Boolean });
參數:該屬性接受上述和以下描述的單個參數:
- objectCaching:當`true`時,該對象將緩存在其他畫布上。當`false`時,除非必要,否則不緩存對象(clipPath)默認為true
以下示例說明了JavaScript中Fabric.js組objectCaching屬性的用法:
例:
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 | Group objectCaching Property
</b>
</div>
<div style="text-align:center;">
<canvas id="canvas" width="500" height="300"
style="border:1px solid green;">
</canvas>
</div>
<script>
// Initiate a Canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate a circle instance
var circle = new fabric.Circle({
radius:100,
fill:'lightgreen',
scaleY:0.6,
originX:'center',
originY:'center'
});
// Initiate a text instance
var text = new fabric.Text('GeeksforGeeks', {
fontSize:25,
originX:'center',
originY:'center'
});
// Initiate a Group instance
var group = new fabric.Group([ circle, text ], {
cornerStyle:'circle',
objectCaching:false
});
// Render the Group in canvas
canvas.add(group);
canvas.centerObject(group);
</script>
</body>
</html>
輸出:
相關用法
- Fabric.js Text objectCaching屬性用法及代碼示例
- Fabric.js Polygon objectCaching屬性用法及代碼示例
- Fabric.js Polyline objectCaching屬性用法及代碼示例
- Fabric.js Path objectCaching屬性用法及代碼示例
- Fabric.js Itext objectCaching屬性用法及代碼示例
- Fabric.js ActiveSelection objectCaching屬性用法及代碼示例
- Fabric.js Group fillRule屬性用法及代碼示例
- Fabric.js Group top屬性用法及代碼示例
- Fabric.js Group subTargetCheck屬性用法及代碼示例
- Fabric.js Group strokeUniform屬性用法及代碼示例
- Fabric.js Group strokeMiterLimit屬性用法及代碼示例
- Fabric.js Group flipY屬性用法及代碼示例
- Fabric.js Group borderColor屬性用法及代碼示例
- Fabric.js Group flipX屬性用法及代碼示例
- Fabric.js Group hasBorders屬性用法及代碼示例
- Fabric.js Group minScaleLimit屬性用法及代碼示例
- Fabric.js Group lockSkewingY屬性用法及代碼示例
- Fabric.js Group lockSkewingX屬性用法及代碼示例
- Fabric.js Group dirty屬性用法及代碼示例
- Fabric.js Group lockScalingFlip屬性用法及代碼示例
- Fabric.js Group cornerStyle屬性用法及代碼示例
- Fabric.js Group centeredScaling屬性用法及代碼示例
- Fabric.js Group cornerSize屬性用法及代碼示例
- Fabric.js Group centeredRotation屬性用法及代碼示例
注:本文由純淨天空篩選整理自thacker_shahid大神的英文原創作品 Fabric.js Group objectCaching Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。