-
Hi!! I'm using a lot of Fabric js functionalities for an e-commerce project where the users can customize their products. In that way, i want to do dynamic aligning in objects for a better user experience. For that, i used the "initAligningGuidelines" base from Fabric.js library. My first approach was this: Anyway, i search for that type of aligning and my new code was based in this Stack Overflow question: https://stackoverflow.com/questions/61340776/align-object-to-canvas-in-fabricjs and i realized that the aligning depends in the So, after the explanation above, i created a JSFiddle with the issue: https://jsfiddle.net/Danex4517/L65fvz2b/37/. Thanks for the help in advance!! :D |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
When you set the object's left value, you should use a |
Beta Was this translation helpful? Give feedback.
-
Not sure if you solved already. The issue with the bounding box is that you have to consider the mouse position instead of the object one. For the use case of aligning horizontally, You can reference each object aCoords x position, and on mousemove, if one of those coords is at the snapping position distance, you change the object left for the current difference between acoord.x and your snapping boundary. |
Beta Was this translation helpful? Give feedback.
When you set the object's left value, you should use a
Math.max()
statement so that if the drag position is larger than the boundary then it uses the drag position insteadactiveObject.set('left', Math.max(left, activeObject.left))
https://jsfiddle.net/melchiar/xu7fedgj/