您需要设置
subTargetCheck
对于组对象为true,然后您可以从包含数组的事件访问子目标
subTargets[]
var canvas = new fabric.Canvas('c');
var rect = new fabric.Rect({
width:100,height:100,left:10,top:10,fill:'red'
});
var circle = new fabric.Circle({
left:150,top:10,fill:'green',radius:50
});
var group = new fabric.Group([rect,circle],{
left:20,
top:20,
subTargetCheck: true
});
canvas.add(group);
group.on('mousedown',onMouseDown);
function onMouseDown(option){
option.subTargets[0] && console.log(option.subTargets[0].type)
}
canvas{
border: 1px solid #000;
}
<script src="https://rawgit.com/kangax/fabric.js/master/dist/fabric.js"></script>
<canvas id="c" width="400" height="400"></canvas>