Jem
Jem

Reputation: 6406

Original position of a draggable in jQuery UI?

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,

Upvotes: 2

Views: 8345

Answers (1)

Roko C. Buljan
Roko C. Buljan

Reputation: 206028

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);
    }
});

Upvotes: 7

Related Questions