您好,欢迎访问一九零五行业门户网

如何使用FabricJS设置Circle的垂直比例因子?

在本教程中,我们将学习如何使用 fabricjs 设置圆的垂直比例因子。圆形是 fabricjs 提供的各种形状之一。为了创建一个圆圈,我们必须创建一个 fabric.circle 类的实例并将其添加到画布中。正如我们可以指定圆形对象在画布中的位置、颜色、不透明度和尺寸一样,我们也可以设置圆形对象的垂直比例。这可以通过使用 scaley 属性来完成。
语法new fabric.circle({ scaley : number }: object)
参数选项(可选) - 此参数是一个对象 为我们的圈子提供额外的定制。使用此参数,可以更改与以scaley为属性的对象相关的颜色、光标、描边宽度和许多其他属性等属性。
选项键scaley - 此属性接受数字值。分配的值决定垂直对象比例因子。默认值为1。
示例1不使用scaley时的默认外观
让我们看一个在不使用 scaley 属性时显示圆形对象外观的示例。默认情况下,圆形对象的垂直比例因子为 1。scaley 确定沿 y 轴调整对象大小的变换。
<!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>setting the vertical scale factor of a circle using fabricjs</h2> <p>notice the vertical scale factor of the circle. here we have not used the <b>scaley</b> property, but by default, it is set to 1. </p> <canvas id="canvas"></canvas> <script> // initiate a canvas instance var canvas = new fabric.canvas("canvas"); var circle = new fabric.circle({ left: 115, top: 50, padding: 7, radius: 50, fill: "#85bb65" }); canvas.add(circle); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); </script> </body></html>
示例 2将 scaley 属性作为键传递
在此示例中,我们传递 scaley 属性作为键,值为2。这意味着圆形对象在垂直方向的比例因子加倍。
<!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>setting the vertical scale factor of a circle using fabricjs</h2> <p>notice the vertical scale factor of the circle. here we have set <b>scaley</b> at 2, so the object appears elongated on the y-axis. </p> <canvas id="canvas"></canvas> <script> // initiate a canvas instance var canvas = new fabric.canvas("canvas"); var circle = new fabric.circle({ left: 115, top: 50, padding: 7, radius: 50, fill: "#85bb65", scaley: 2 }); canvas.add(circle); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); </script> </body></html>
以上就是如何使用fabricjs设置circle的垂直比例因子?的详细内容。
其它类似信息

推荐信息