How to get the new coordinates of an image after a drag and drop?

A dummy question: Without using Transform Manager, when i drag an element (no centerReg()) from one place to another, how can i get its new coordinates? which will later be saved to a json file.
An alternative: i tried to use place(). It sems to work. Maybe, there is a better way?

add the drag() as you probably have - but then to find out when you drop use the pressup event.

so circle.drag();

circle.on("pressup", ()=>{});

Then in that function you ask for circle.x and circle.y.

If you want them to be remembered across browser loads then store those in localStorage

localStorage.coords = JSON.stringify({x:circle.x, y:circle.y});

But then as you load you would need to check if you have those

if (localStorage.coords) {
const coords = JSON.parse(localStorage.coords);
circle.loc(coords);
}

Or use bind() which can bind to localStorage.

Thank You!

1 Like