javascript - Bind events to object in fabricJS - Stack Overflow

Using latest Fabric.js, I have the code:var imageAdded = new Image();imageAdded.onload = function (img

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 want to alert when I select an object but no alert is showed because the function where I made a ment in the code doesn't work.
  • I tried this link but still can't make it possible.

I appreciate every suggestion. Thank you!

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 want to alert when I select an object but no alert is showed because the function where I made a ment in the code doesn't work.
  • I tried this link but still can't make it possible.

I appreciate every suggestion. Thank you!

Share Improve this question edited May 23, 2017 at 11:44 CommunityBot 11 silver badge asked Jan 6, 2016 at 3:10 MesMes 1774 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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);});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745144512a4613585.html

相关推荐

  • javascript - Bind events to object in fabricJS - Stack Overflow

    Using latest Fabric.js, I have the code:var imageAdded = new Image();imageAdded.onload = function (img

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信