在本教學中,我們將學習如何使用 FabricJS 隱藏圓的控制邊框。圓形是 FabricJS 提供的各種形狀之一。為了創建一個圓圈,我們將建立一個 Fabric.Circle 類別的實例並將其新增至畫布。我們可以透過多種方式自訂控制邊框,例如添加特定顏色、破折號圖案等。但是,我們也可以使用 hasBorders 屬性來完全消除邊框。
new fabric.Circle({ hasBorders: Boolean }: Object)
#選項(可選) - 此參數是一個物件< /em> 為我們的圈子提供額外的客製化。使用此參數,可以變更與 hasBorders 為屬性的物件相關的顏色、遊標、描邊寬度等屬性。
#hasBorders - 此屬性接受布林值< /strong> 值,當設定為False 時,將不會渲染控制邊框。預設值為True。
Circle 物件控制邊框的預設外觀< /strong>
讓我們看一段程式碼,顯示控制圓邊框的預設外觀。由於hasBorders屬性的預設值為True,因此在選擇圓形物件時渲染邊框。
<!DOCTYPE html> <html> <head> <!-- Adding the Fabric JS Library--> <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script> </head> <body> <h2>Hiding the controlling borders of a circle using FabricJS</h2> <p>Select the object and notice its controlling borders. This is the default appearance. Although we have not used the <b>hasBorders</b> property, it is by default set to True.</p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); var circle = new fabric.Circle({ left: 215, top: 100, fill: "white", radius: 50, stroke: "#c154c1", strokeWidth: 5 }); // Adding it to the canvas canvas.add(circle); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
將hasBorders 當作鍵傳遞並為其指派「false」值
如果hasBorders 屬性被分配了一個False 值,邊框將不再被渲染。這意味著當我們選擇圓形物件時,控制邊框將被隱藏。
<!DOCTYPE html> <html> <head> <!-- Adding the Fabric JS Library--> <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script> </head> <body> <h2>Hiding the controlling borders of a circle using FabricJS</h2> <p>Select the object and now you will no longer be able to see its controlling borders, as we have set <b>hasBorders</b> as False.</p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); var circle = new fabric.Circle({ left: 215, top: 100, fill: "white", radius: 50, stroke: "#c154c1", strokeWidth: 5, hasBorders: false }); // Adding it to the canvas canvas.add(circle); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
以上是如何使用 FabricJS 隱藏圓的控制邊框?的詳細內容。更多資訊請關注PHP中文網其他相關文章!