Fabric.js - How to select a specific object by type

1.7k views Asked by At

I'm trying to figure out how to grab a fabric object and change its properties when its moving. I have three different shapes. A fabric.Rect, fabric.Circle and fabric.Triangle. They all have different property values so if anyone knows how to change them accordingly that would be greatly appreciated.

This is how I tried doing it with no success.

canvas.on('object:moving', function(e) {
  var activeObject = e.target;
  activeObject.shadow = null;


   if (e.target = fabric.Rect){
    activeObject.height = 40;
    activeObject.width = 40;
    };

    if (e.target = fabric.Circle){
     activeObject.radius = 20; 
     };

    if (e.target = fabric.Triangle){
     activeObject.height = 40;
     activeObject.width = 35 
     };


});   
1

There are 1 answers

3
Harsh Makani On
function onObjectSelected(e) {
  console.log(e.target.get('type'));
}
canvas.on('object:selected', onObjectSelected);