In this tutorial, we will learn how to hide the control border of an ellipse using FabricJS. The oval is one of the various shapes provided by FabricJS. In order to create an ellipse, we must create an instance of the Fabric.Ellipse class and add it to the canvas. We can customize the control borders in many ways, such as adding specific colors, dash patterns, etc. However, we can also eliminate the borders entirely using the hasBorders property.
new fabric.Ellipse({ hasBorders: Boolean }: Object)
Options (optional) - This parameter is a Object< /em> Provides additional customization for our ellipse. Using this parameter, you can change the color, cursor, stroke width, and many other properties associated with the object for which hasBorders is a property.
##hasBorders - This property accepts a Boolean Value em>When set to False, the control border will not be rendered. The default value is True.
The default appearance of the ellipse object control border< /strong>
The following example shows the default appearance of the ellipse control border . Since the default value of thehasBorders property is "true", borders are rendered when the ellipse object is selected.
<!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>How to hide the controlling borders of an Ellipse using FabricJS?</h2> <p>Select the object and you would get to see the controlling borders. This is the default behavior.</p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); // Initiate an ellipse instance var ellipse = new fabric.Ellipse({ left: 105, top: 100, fill: "white", rx: 100, ry: 60, stroke: "#c154c1", strokeWidth: 5, }); // Adding it to the canvas canvas.add(ellipse); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
Pass hasBorders as key and assign it the value "false"
ifThe >hasBorders property is assigned a value of "false" and the borders will no longer be rendered. This means that when we select the ellipse object, the control border will be hidden.
<!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>How to hide the controlling borders of an Ellipse using FabricJS?</h2> <p>Select the object. Now you won't get to see the controlling borders because we have set the <b>hasBorders</b> property to False. </p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); // Initiate an ellipse instance var ellipse = new fabric.Ellipse({ left: 105, top: 100, fill: "white", rx: 100, ry: 60, stroke: "#c154c1", strokeWidth: 5, hasBorders: false, }); // Adding it to the canvas canvas.add(ellipse); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
The above is the detailed content of How to hide the control border of an ellipse using FabricJS?. For more information, please follow other related articles on the PHP Chinese website!