I need to use jQuery UI to restrict the containment area for draggable object with some additional restriction. I need prevent the draggable element from overlapping with ot
This took me quite a bit of fiddling. Basically I created a droppable on the element you want to avoid, then set a boolean when the drag is over it. I then use that in an undocumented revert function override to cancel the drop. It only works if #dragMe is fully over #butNotHere:
$(document).ready(function(){
var shouldCancel = false;
$('#dragMe').draggable({
containment: '#moveInHere',
revert: function(){
if (shouldCancel) {
shouldCancel = false;
return true;
} else {
return false;
}
}
});
$('#butNotHere').droppable({
over: function(){
shouldCancel = true;
},
out: function(){
shouldCancel = false;
}
});
});
Check out the working demo and feel free to play with it: http://jsfiddle.net/H59Nb/31/