最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bind events to object in fabricJS - Stack Overflow

programmeradmin1浏览0评论

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);});
发布评论

评论列表(0)

  1. 暂无评论