Droppable
jQuery UI Droppable
Overview
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'):
- ui.draggable - current draggable element, a jQuery object.
- ui.helper - current draggable helper, a jQuery object
- ui.position - current position of the draggable helper { top: , left: }
- ui.offset - current absolute position of the draggable helper { top: , left: }
Dependencies
- UI Core
- UI Widget
- UI Mouse
- UI Draggable
Example
$("#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>
Options
Events
Methods
-
destroy
- Signature:
- .droppable( "destroy" )
Remove the droppable functionality completely. This will return the element back to its pre-init state.
-
disable
- Signature:
- .droppable( "disable" )
Disable the droppable.
-
enable
- Signature:
- .droppable( "enable" )
Enable the droppable.
-
option
- Signature:
- .droppable( "option" , optionName , [value] )
Get or set any droppable option. If no value is specified, will act as a getter.
-
option
- Signature:
- .droppable( "option" , options )
Set multiple droppable options at once by providing an options object.
-
widget
- Signature:
- .droppable( "widget" )
Returns the .ui-droppable element.
Theming
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.
Sample markup with jQuery UI CSS Framework classes
<div class="ui-droppable"></div>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>.