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

前端 未结 2 1272
悲哀的现实
悲哀的现实 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:30

    FabricJS now supports this natively through 'setAngle', along with 'snapThreshold' property.

    https://github.com/kangax/fabric.js/pull/3383

    Example:

    canvas.add(new fabric.Circle({
      snapAngle: 90,
      snapThreshold: 45,
      left: 100, 
      top: 100, 
      radius:50,
      fill: '#9f9', 
      centeredRotation: true
    }));
    

    https://jsfiddle.net/2t2d1zj9/1/

提交回复
热议问题