In dealing with offset with fabric.js - what is the best approach?
I'm basically allowing a user to draw a box, and I want to make sure I have the box drawn at the exact start and ending coordinates of the dragging action.
http://jsfiddle.net/mojo5000/P7gAC/4/
...
left: x + width/2 - 8,
top: y + height/2 - 8,
...
I basically had to a little rigging with the left and top values. It seems to work. Is there a better way to do this?
You have not factored in the positioning of the canvas element. Use the following:
As you can see in the code, the coordinates of the canvas element are given by:
canvas._offset.left
andcanvas._offset.top