FabricJS Catch click on object inside group

后端 未结 7 698
感动是毒
感动是毒 2021-01-17 19:06

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

7条回答
  •  野的像风
    2021-01-17 19:38

    I downloaded fabricjs from asturur repo. build fabric.js file

    node build.js modules=ALL exclude=json,gestures
    

    and it works!

    Then you can use events on objects in the groups.

    canvas._objects[0]._objects[0].on('mousedown', function(e){ this.stroke = 'black'});
    

    In my app i decided to search for events from mousedown callback

    group.on('mousedown', function(e){
        var innerTarget  = group._searchPossibleTargets(e.e);
        console.log(innerTarget);
    });
    
    group._searchPossibleTargets = function(e) {
        var pointer = this.canvas.getPointer(e, true);
        var i = objects.length,
            normalizedPointer = this.canvas._normalizePointer(this, pointer);
    
        while (i--) {
            if (this.canvas._checkTarget(normalizedPointer, this._objects[i])) {
                return this._objects[i];
            }
        }
        return null;
    }
    

提交回复
热议问题