我试过下面的代码:
canvas.setActiveGroup(new fabric.Group(canvas.getObjects())).renderAll();
但它选择整个组作为单个实体。
答案 0 :(得分:0)
这里我有一个解决方案,在鼠标悬停时我选择鼠标指针经过的元素。
window.canvas = new fabric.Canvas('c', {perPixelTargetFind: true});
var shadow = {
color: 'rgba(0,0,0,0.6)',
blur: 20,
offsetX: 10,
offsetY: 10,
opacity: 0.6,
fillShadow: true,
strokeShadow: true
}
var rect = new fabric.Rect({
left: 120,
top: 100,
fill: "#FF0000",
stroke: "#000",
width: 100,
height: 100,
strokeWidth: 10,
opacity: .8
});
var rect1 = new fabric.Rect({
left: 0,
top: 100,
fill: "#FF0000",
stroke: "#000",
width: 100,
height: 100,
strokeWidth: 10,
opacity: .8
});
canvas.on('mouse:move', function(e){
console.log('over1',e.target)
if(e.target && e.target !== canvas.getActiveObject())
canvas.setActiveObject(e.target)
})
rect.setShadow(shadow);
canvas.add(rect);
canvas.add(rect1);

<canvas id="c" width="300" height="300"></canvas>
&#13;