i am new in fabric js want to set the drag limit
i have also try with https://github.com/kangax/fabric.js/wiki/Working-with-events
not able to get the solution.
please check the attached image, object can move anyware but it should be display in red area only.i want this. help me...thanks in advance !!
SEE THE WORKING EXAMPLE It's as simple as a water try this
just use this js
Hope this will help you. Njoy coding :) now u can have the same clipping region for every object supported by Fabric.js for transformation and moving. try it :).
While Orangepill's answer is correct, it produces a "stuttering" when your object hits the object bounds. If you have a rectangular bounding box (and not a complex bounding object) an alternative is to allow the object to be dragged along the bounds and "slide" along the bounding box. You do this by capping the coordinates values and letting the other dimension move as usual. An example snippet would look like so:
See this example in JSFiddle here
What had worked for me is to create an event listener for the
object:moving
event. When the move is happening you update the goodtop and goodleft variables and once you are out of bounds to reposition the object to the last good points.Felix Fung's answer was a starting point, but there are many things to consider. Here is a version that accounts for some of them.
It handles the canvas having a viewport transform (ie, zoomed/panned) and objects that are center-origined instead of left/top-origined. It also constrains objects wider/taller than the viewport to the top/left instead of the bottom/right.