Droppable
Create drop targets that accept draggable elements with hover and drop events.
Code
$(".draggable-item").draggable({ revert: "invalid" });
$("#dropzone").droppable({
accept: ".draggable-item",
hoverClass: "drop-hover",
activeClass: "drop-active",
tolerance: "fit",
drop: function(event, ui) {
$(this).addClass("dropped").find("p").html("Dropped!");
ui.draggable.css("background", "green");
},
over: function(event, ui) {
$(this).addClass("over");
},
out: function(event, ui) {
$(this).removeClass("over").removeClass("dropped");
}
});
// Tolerance values: 'fit' (fully inside), 'intersect' (50% overlap),
// 'pointer' (mouse over), 'touch' (any overlap)Explanation
Pairs with draggable to build drop interactions; the accept selector restricts which draggables are valid. The tolerance option controls how much overlap is required to trigger the over/out/drop events. The hoverClass and activeClass make it easy to style state changes during interaction.
More jQuery UI Snippets
Draggable
Make elements draggable with axis, containment, and event callbacks.
Resizable
Add resize handles with min/max constraints and aspect ratio lock.
Sortable
Reorder list items via drag-and-drop and persist the new order.
Accordion
Collapsible content panels with only one section expanded at a time.
Datepicker
Calendar widget with date range limits, formatting, and inline mode.
Dialog
Modal window with buttons, animations, and dynamic open/close.