I have a little problem with jQuery UI\'s droppable component, but I\'m not quite sure whether I have that problem because of my code or because of a bug in the component.>
Check the droppable element's bounds against the parent container and break the execution of the function if the droppable's bottom is above the parent's top or the droppable's top is beneath the parent's bottom:
$('.item').droppable( {
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
accept: "#draggable",
drop: function( event, ui ) {
var cTop = $(this).closest(".box").position().top + parseInt($(this).closest(".box").css("margin-top"));
var cBtm = $(this).closest(".box").position().top + parseInt($(this).closest(".box").css("margin-top")) + $(this).closest(".box").height();
var dTop = $(this).position().top + parseInt($(this).css("margin-top"));
var dBtm = $(this).position().top + parseInt($(this).css("margin-top")) + $(this).height()
if (dBtm > cTop && dTop < cBtm) {
alert("Dropped.");
}
}
});
Example: http://jsfiddle.net/lthibodeaux/2p56Y/6/
I realize it's not elegant, but it seems workable. I admit to only cursory testing of this script.