I'm making a game and I need to grab the position of an element before dragging it. I'm using the Droppable function of jQuery UI.
jQuery
$("div.cesto").off().droppable({
accept : "span.piece",
// Quando coloca o mouse em cima do cesto
over : function(){
$(this).addClass("amp");
media.replay("boeing-02");
media.play("boeing-02");
},
// Quando sai com o mouse de cima do cesto
out : function(){
$(this).removeClass("amp");
},
drop : function(event, ui){
var cesto = $(this);
// Posições atual do elemento
var positionTopPiece = ui.position.top;
var positionLeftPiece = ui.position.left;
In the last two lines of the code, notice that I'm picking up the current position of the element. That is, I click on the element, drag and drop it and it gives me the position.
But that's not what I want. I want you to save your TOP and LEFT positions to use later in a function before dragging it.
That is, the element will return to its home position depending on a result.
I'm in the Droppable documentation - link
But I can not find a function that does what I need.
position
Type: Object
Current CSS position of the draggable helper as {top, left} object.
offset
Type: Object
Current offset position of the draggable helper as {top, left} object.