Set object drag limit in Fabric.js

前端 未结 5 1231
面向向阳花
面向向阳花 2020-12-24 00:24

i am new in fabric js want to set the drag limit\"enter

i have also try with https://

5条回答
  •  清酒与你
    2020-12-24 01:23

    What had worked for me is to create an event listener for the object:moving event. When the move is happening you update the goodtop and goodleft variables and once you are out of bounds to reposition the object to the last good points.

    var goodtop, goodleft, boundingObject;
    
    canvas.on("object:moving", function(){
        var obj = this.relatedTarget;
        var bounds = boundingObject;
        obj.setCoords();
        if(!obj.isContainedWithinObject(bounds)){
            obj.setTop(goodtop);
            obj.setLeft(goodleft);
            canvas.refresh();    
        } else {
            goodtop = obj.top;
            goodleft = obj.left;
        }  
    });
    

提交回复
热议问题