onclickfabricjs

FabricJS Catch click on object inside group


I have tried many thing like calculating location, handling with the event we do have in original fabricjs. Does any have done this before?


Solution

  • It is possible to listen for events on the inner object by adding the option: subTargetCheck: true to the fabric.Group object.

        // create a group
        let group = new fabric.Group([circle, rect], {
            subTargetCheck: true
        });
    
        circle.on('mousedown', function(e) { 
            // e.target should be the circle
            console.log(e.target);
        });