Original position of a draggable in jQuery UI?

Jem picture Jem · Sep 10, 2012 · Viewed 7.9k times · Source

As a drop happens, I need to recover the original position of the draggable:

$('.article').droppable( {

    drop: function(even, ui){

        // ui.draggable.???
    }
});

Since there is a "revert: "invalid" property on my draggable, I assume the original position is store somewhere. How can I find it?

Thanks,

Answer

Roko C. Buljan picture Roko C. Buljan · Sep 10, 2012

You can use: ui.helper.position()

jsBin demo

var startPos;
$( ".article" ).draggable({
    revert: "invalid",
    start: function(evt, ui){
        startPos = ui.helper.position();
    }
});

$(".parent").droppable({
    drop: function(evt, ui){
        // NOW RETRIEVE COORDINATES STORED BY THE DRAGGABLE :START
        var x = startPos.left;
        var y = startPos.top;
        alert(x+' '+y);
    }
});