Search code examples
fabricjs

How to animate rotate around center in fabric js


When you use one of the handle bars to rotate an object in fabricjs it will rotate the object around center. However, when using

tri.animate('angle', 45, {
  onChange: canvas.renderAll.bind(canvas)
});

It will rotate around the top-left corner. How to rotate around center just like with the handle bar?

Example: http://jsfiddle.net/QQ6eA/1/


Solution

  • Add:

    originX: 'center',
    originY: 'center',
    

    to your triangle creation code.