I have an element, let’s say a div, that I want to be able to drag and drop into another div. If the element isn’t dragged into the other div I would like it to animate back to it’s initial position. The draggable divs are relatively positioned. So, my question is what’s the best approach? Is there a method in jQuery UI which will allow it to animate back? Or am I going to have to write it? If I do, here’s my strategy:
-
get coordinates of the draggable div on start of drag using
$('#draggableElement').css('left'), and$('#draggableElement').css('top') -
On drag complete use the jQuery .animate to put it back in place.
Is that strategy correct? Or is there something more efficient I could be doing?
Have a look at this
and maybe the helper of a jquery ui draggable options -> helper.
I think this should help you. If not, please specify your question.