In this jsFiddle I am getting one issue. Let me describe
When I drag any element contains "N" to other <td>
is working good. But after that when I try to drag any element to it's original position is not working.
My expectation : When any element is moved to other place then old place must be allow to accept other element.
Following is the code:
$(function () {
$(".dragDiv").draggable({
create: function () {
$(this).data('position', $(this).position())
},
revert: 'invalid',
stop: function () {
$(this).draggable('option', 'revert', 'invalid');
}
});
$('.dragDiv').droppable({
greedy: true,
tolerance: 'touch',
drop: function (event, ui) {
ui.draggable.draggable('option', 'revert', true);
}
});
$(".mainTable tr td").droppable({
drop: function (event, ui) {
console.log(JSON.stringify($(this).attr('id')));
console.log(JSON.stringify(ui.draggable.attr("id")));
snapToMiddle(ui.draggable, $(this));
},
accept: function () {
return $(this).find("*").length == 0;
}
});
});
function snapToMiddle(dragger, target) {
var topMove = target.position().top - dragger.data('position').top + (target.outerHeight(true) - dragger.outerHeight(true)) / 2;
var leftMove = target.position().left - dragger.data('position').left + (target.outerWidth(true) - dragger.outerWidth(true)) / 2;
dragger.animate({
top: topMove,
left: leftMove
}, {
duration: 100,
easing: 'easeOutBack'
});
}