07-20-2023, 02:51 PM
Hello **I use fabricjs to play with the html canvas**.
I create the canvas and i add group of objects on it.
On a group of objects, I need to keep fixed width & height for some objects while I scale the object.
I use the **'object:scaling' event** to get the active object when it changes size, I read each object of the group and I assign **element[i].set({'radius':5})** on the group objects that I want to be unchanged.
**But the result is that , all the group object to resize.**
I show you the snippet of the **object:scaling event** :
canvas.on('object:scaling',function(e){
var activeObject1 = e.target;
var elements = e.target._objects;
var count_elements = elements.length;
for(var i = 0; i < count_elements; i++) {
var type = elements[i].typeCircle;
if(type == "parts"){
//elements[i].set({"radius":8,"fill":"#abcde2","stroke":"#367827"});
//elements[i].set('radius',8);
/*elements[i].setWidth(16);
elements[i].setHeight(16);
elements[i].currentWidth = 16;
elements[i].currentHeight = 16;
elements[i].scaleX = 1;
elements[i].scaleY = 1;
console.log(elements[i]);
canvas.renderAll();*/
}
}
});
What should I write into the for loop to keep fixed size on some objects?
everything that I used above, they don't work except for the **"fill":"#abcde2","stroke":"#367827"**
If anyone has faced something similar on fabricjs, please let me know .
I create the canvas and i add group of objects on it.
On a group of objects, I need to keep fixed width & height for some objects while I scale the object.
I use the **'object:scaling' event** to get the active object when it changes size, I read each object of the group and I assign **element[i].set({'radius':5})** on the group objects that I want to be unchanged.
**But the result is that , all the group object to resize.**
I show you the snippet of the **object:scaling event** :
canvas.on('object:scaling',function(e){
var activeObject1 = e.target;
var elements = e.target._objects;
var count_elements = elements.length;
for(var i = 0; i < count_elements; i++) {
var type = elements[i].typeCircle;
if(type == "parts"){
//elements[i].set({"radius":8,"fill":"#abcde2","stroke":"#367827"});
//elements[i].set('radius',8);
/*elements[i].setWidth(16);
elements[i].setHeight(16);
elements[i].currentWidth = 16;
elements[i].currentHeight = 16;
elements[i].scaleX = 1;
elements[i].scaleY = 1;
console.log(elements[i]);
canvas.renderAll();*/
}
}
});
What should I write into the for loop to keep fixed size on some objects?
everything that I used above, they don't work except for the **"fill":"#abcde2","stroke":"#367827"**
If anyone has faced something similar on fabricjs, please let me know .