In this tutorial, we will learn how to set the width of a triangle using FabricJS. Triangle is one of the various shapes provided by FabricJS. In order to create a triangle, we must create an instance of the Fabric.Triangle class and add it to the canvas.
We can manipulate the triangle object by changing its position, opacity, stroke and its dimensions. FabricJS allows us to control the size of objects using the width and height properties.
new Fabric.Triangle({ width: Number }: Object)
Width - This property accepts a numeric value that allows us to specify The width of the object. Its default value is 100.
width Default behavior of properties< /p>
Let’s look at a code example Understand the default behavior of the width attribute.
宽度属性的默认行为 可以看到三角形的宽度默认为100 // 启动画布实例 var canvas = new Fabric.Canvas("canvas"); canvas.setWidth(document.body.scrollWidth); 画布.setHeight(250); // 初始化一个三角形对象 var triangle = new Fabric.Triangle({ 左:60, 顶部:50, 填写:“#b0e0e6”, 身高:90, }); // 将其添加到画布中 canvas.add(三角形);
Passing the width attribute as key
Now we have the width The attribute is assigned a value of 180px, and we can see the change in its width.
将宽度属性作为键传递 您可以看到三角形的宽度现在固定为 180。 // 启动画布实例 var canvas = new Fabric.Canvas("canvas"); canvas.setWidth(document.body.scrollWidth); 画布.setHeight(250); // 初始化一个三角形对象 var triangle = new Fabric.Triangle({ 左:60, 顶部:50, 填写:“#b0e0e6”, 身高:90, 宽度:180, }); // 将其添加到画布中 canvas.add(三角形);
The above is the detailed content of How to set the width of a triangle using FabricJS?. For more information, please follow other related articles on the PHP Chinese website!