Reputation: 15
How do you get a specific object from Fabric.js, and determine which one you got? Like calling canvas.getSelectedObject()
and then determining if the
returned object is an IText
or a Circle
or something else.
Thanks.
Upvotes: 0
Views: 82
Reputation: 2872
I believe what you're looking for is the object type
property. You can use it like this:
var obj = canvas.getActiveObject();
switch(obj.type) {
case "circle":
//stuff to do if selection is a circle
break;
case "itext":
//stuff to do if selection is a itext
break;
}
Upvotes: 1
Reputation: 503
I think instanceof
may be what you want.
var c = new fabric.Circle()
console.log(c instanceof fabric.Circle) // true
Upvotes: 0