Rotation and Scaling controls are off after using setAngle() in Fabric.js

前端 未结 2 1291
悲哀的现实
悲哀的现实 2021-01-15 22:44

I want to let users rotate objects on the Fabric.js powered canvas, but limit their rotation to 90 deg increments. Idea is that as they rotate and then stop, the object woul

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-15 23:15

    Run setCoords() after setAngle(). This will update the position of the controls. Tried it in your fiddle. Works fine.

       canvas.on("object:modified", function(modEvtData) {
         // modified fires after object has been rotated 
         var modifiedObj = modEvtData.target;
         if (modifiedObj.angle && snapAfterRotate) {
             modifiedObj.setAngle(lastClosestAngle).setCoords();
             snapAfterRotate = false;
             canvas.renderAll();
         }
       })
    

    regards, Benick

提交回复
热议问题