Mixed code from 2 samples
$('#floor').droppable({
tolerance: 'fit'
});
$('.draggable-div').draggable({
revert: 'invalid',
stop: function(){
$(this).draggable('option','revert','invalid');
$(this).find('.undo').show();
}
});
$('.draggable-div').find('.undo').click(function(i, e) {
var $div = $(this).parent();
revertDraggable($div);
});
$('#floor').droppable({
greedy: true,
tolerance: 'touch',
drop: function(event,ui){
// ui.draggable.draggable('option','revert',true);
if (!ui.draggable.data("originalPosition")) {
ui.draggable.data("originalPosition",
ui.draggable.data("draggable").originalPosition);
}
$(this).find('.undo').show();
}
});
function revertDraggable($selector) {
$selector.each(function() {
var $this = $(this),
position = $this.data("originalPosition");
if (position) {
$this.animate({
left: position.left,
top: position.top
}, 500, function() {
$this.data("originalPosition", null);
});
}
});
$selector.find('.undo').hide();
}
See full code here.
It works now