0

我想动态地将矩形添加到组中。但是当我在顶部或左侧添加时,组的左上角会跳转到添加的矩形的左上角。请帮我解决。

我如何添加矩形:

let canvas = new fabric.Canvas('draw');
let group = new fabric.Group('', {
                     objectCaching: false,
                     hasControls: false,
                     hasBorders: false,
                     hasRotatingPoint: false,
                     subTargetCheck: true,
                });
group.addWithUpdate(new fabric.Rect({top:0,left:0,width:100,height:200}));
canvas.add(group);
canvas.renderAll();
group.on('moving', move);
function move(e) {
    let trCorner = e.target.calcCoords().tr;
    let viewPortTSide = e.target.canvas.calcViewportBoundaries().tl.y;
    if (viewPortTSide - trCorner.y < -10) {
        group.addWithUpdate(new fabric.Rect({top:-400,left:-200, height: 300, width: 200}))
    }
}

4

0 回答 0