I found an acceptable solution. It is based on the mouse position information that you can get from ui.helper.
At first, this solution was not working for me because, at least in my specific case, sometimes the drag helper itself was returned by document.elementFromPoint(). The solution that made this approach working was to temporarily hide the helper. This is not a clean solution but I do not see a better one.
$(dropElement).droppable({
drop: function(event, ui) {
var mouseXPosition = ui.helper.position().left,
mouseYPosition = ui.helper.position().top;
$(ui.helper).hide();
var targetElement = document.elementFromPoint(mouseXPosition, mouseYPosition);
$(ui.helper).show();
if (targetElement.id === $(dropElement).attr('id')) {
// do your drop logic here
}
}
});
As a side node, the mentioned solution based on mouseleave did not work for me, because the children of the droppable contain themself draggable elements that can be dropped into the droppable, and in this case if something is dragged out of an element with a mouseleave event handler registered, mouseleave is not fired. But using event handlers for such functionalities should be avoided anyway.