The jQuery UI Droppable plugin makes selected elements droppable (meaning they accept being dropped on by draggables). You can specify which (individually) or which kind of draggables each will accept.
All callbacks receive two arguments: The original browser event and a prepared ui object, view below for a documentation of this object (if you name your second argument 'ui'):
$("#draggable").draggable(); $("#droppable").droppable({ drop: function() { alert('dropped'); } });
<!DOCTYPE html> <html> <head> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <style type="text/css"> #draggable { width: 75px; height: 25px; background: silver; padding: 10px; } #droppable { position: absolute; left: 250px; top: 0; width: 125px; height: 75px; background: gray; color: white; padding: 10px; } </style> <script> $(document).ready(function() { $("#draggable").draggable(); $("#droppable").droppable({ drop: function() { alert('dropped'); } }); }); </script> </head> <body style="font-size:62.5%;"> <div id="droppable">Drop here</div> <div id="draggable">Drag me</div> </body> </html>
This event is triggered when droppable is created.
create
event as an init option.
$( ".selector" ).droppable({
create: function(event, ui) { ... }
});
create
event by type: dropcreate
.
$( ".selector" ).bind( "dropcreate", function(event, ui) {
...
});
This event is triggered any time an accepted draggable starts dragging. This can be useful if you want to make the droppable 'light up' when it can be dropped on.
activate
event as an init option.
$( ".selector" ).droppable({
activate: function(event, ui) { ... }
});
activate
event by type: dropactivate
.
$( ".selector" ).bind( "dropactivate", function(event, ui) {
...
});
This event is triggered any time an accepted draggable stops dragging.
deactivate
event as an init option.
$( ".selector" ).droppable({
deactivate: function(event, ui) { ... }
});
deactivate
event by type: dropdeactivate
.
$( ".selector" ).bind( "dropdeactivate", function(event, ui) {
...
});
This event is triggered as an accepted draggable is dragged 'over' (within the tolerance of) this droppable.
over
event as an init option.
$( ".selector" ).droppable({
over: function(event, ui) { ... }
});
over
event by type: dropover
.
$( ".selector" ).bind( "dropover", function(event, ui) {
...
});
This event is triggered when an accepted draggable is dragged out (within the tolerance of) this droppable.
out
event as an init option.
$( ".selector" ).droppable({
out: function(event, ui) { ... }
});
out
event by type: dropout
.
$( ".selector" ).bind( "dropout", function(event, ui) {
...
});
This event is triggered when an accepted draggable is dropped 'over' (within the tolerance of) this droppable. In the callback, $(this) represents the droppable the draggable is dropped on. ui.draggable represents the draggable.
drop
event as an init option.
$( ".selector" ).droppable({
drop: function(event, ui) { ... }
});
drop
event by type: drop
.
$( ".selector" ).bind( "drop", function(event, ui) {
...
});
Remove the droppable functionality completely. This will return the element back to its pre-init state.
Disable the droppable.
Enable the droppable.
Get or set any droppable option. If no value is specified, will act as a getter.
Set multiple droppable options at once by providing an options object.
Returns the .ui-droppable element.
The jQuery UI Droppable plugin uses the jQuery UI CSS Framework to style its look and feel, including colors and background textures. We recommend using the ThemeRoller tool to create and download custom themes that are easy to build and maintain.
If a deeper level of customization is needed, there are widget-specific classes referenced within the jquery.ui.droppable.css stylesheet that can be modified. These classes are highlighed in bold below.
Note: This is a sample of markup generated by the droppable plugin, not markup you should use to create a droppable. The only markup needed for that is <div></div>.