Mes
Mes

Reputation: 177

Bind events to object in fabricJS

Using latest Fabric.js, I have the code:

var imageAdded = new Image();
imageAdded.onload = function (img) {
    var imgAdded = new fabric.Image(imageAdded, {
        clipName: picID,
        clipTo: function (ctx) {
            return _.bind(clipByName, imgAdded)(ctx)
        }
    });
    canvas.add(imgAdded);

    imgAdded.on("object:selected", function (e) { // It doesn't pass this function
        alert(e.target.clipName + " is selected");
        e.target.clipTo = null;
        canvas.renderAll();
    });
};

I appreciate every suggestion. Thank you!

Upvotes: 2

Views: 5868

Answers (1)

AndreaBogazzi
AndreaBogazzi

Reputation: 14731

If you want an event for a specific object use:

imgAdded.on("selected", function(){alert(this.clipName);});

if want event for canvas and all objects:

canvas.on("object:selected", function(e){alert(e.target.clipName);});

Upvotes: 5

Related Questions