您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

如何使用 FabricJS 隐藏椭圆的控制边框?

2024/6/27 19:01:59发布41次查看
在本教程中,我们将学习如何使用 fabricjs 隐藏椭圆的控制边框。椭圆形是 fabricjs 提供的各种形状之一。为了创建一个椭圆,我们必须创建一个 fabric.ellipse 类的实例并将其添加到画布中。我们可以通过多种方式自定义控制边框,例如添加特定颜色、破折号图案等。但是,我们也可以使用 hasborders 属性完全消除边框。
语法new fabric.ellipse({ hasborders: boolean }: object)
参数选项(可选)- 此参数是一个对象 为我们的椭圆提供额外的定制。使用此参数,可以更改与 hasborders 为属性的对象相关的颜色、光标、描边宽度和许多其他属性。
选项键hasborders - 此属性接受布尔值当设置为false时,控制边框将不会被渲染。默认值为true。
示例 1椭圆对象控制边框的默认外观
以下示例显示了椭圆形控制边框的默认外观。由于 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>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>
示例 2将 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>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>
以上就是如何使用 fabricjs 隐藏椭圆的控制边框?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product