Droppable Widgetversion added: 1.0
Description: Create targets for draggable elements.
The jQuery UI Droppable plugin makes selected elements droppable (meaning they accept being dropped on by draggables). You can specify which draggables each will accept.
Theming
The droppable widget uses the jQuery UI CSS framework to style its look and feel. If droppable specific styling is needed, the following CSS class names can be used for overrides or as keys for the classes
option:
-
ui-droppable
: The droppable element. When a draggable that can be dropped on this dropppable is activated, theui-droppable-active
class is added. When dragging a draggable over this droppable, theui-droppable-hover
class is added.
Dependencies
Options
accept
"*"
- Selector: A selector indicating which draggable elements are accepted.
-
Function: A function that will be called for each draggable on the page (passed as the first argument to the function). The function must return
true
if the draggable should be accepted.
Initialize the droppable with the accept
option specified:
1
2
3
|
|
Get or set the accept
option, after initialization:
1
2
3
4
5
|
|
activeClass
false
If specified, the class will be added to the droppable while an acceptable draggable is being dragged.
The activeClass
option has been deprecated in favor of the classes
option, using the ui-droppable-active
property.
Initialize the droppable with the activeClass
option specified:
1
2
3
|
|
Get or set the activeClass
option, after initialization:
1
2
3
4
5
|
|
addClasses
true
false
, will prevent the ui-droppable
class from being added. This may be desired as a performance optimization when calling .droppable()
init on hundreds of elements.Initialize the droppable with the addClasses
option specified:
1
2
3
|
|
Get or set the addClasses
option, after initialization:
1
2
3
4
5
|
|
classes
{}
Specify additional classes to add to the widget's elements. Any of classes specified in the Theming section can be used as keys to override their value. To learn more about this option, check out the learn article about the classes
option.
Initialize the droppable with the classes
option specified, changing the theming for the ui-droppable
class:
1
2
3
4
5
|
|
Get or set a property of the classes
option, after initialization, here reading and changing the theming for the ui-droppable
class:
1
2
3
4
5
|
|
disabled
false
true
.Initialize the droppable with the disabled
option specified:
1
2
3
|
|
Get or set the disabled
option, after initialization:
1
2
3
4
5
|
|
greedy
false
true
, any parent droppables will not receive the element. The drop
event will still bubble normally, but the event.target
can be checked to see which droppable received the draggable element.Initialize the droppable with the greedy
option specified:
1
2
3
|
|
Get or set the greedy
option, after initialization:
1
2
3
4
5
|
|
hoverClass
false
If specified, the class will be added to the droppable while an acceptable draggable is being hovered over the droppable.
The hoverClass
option has been deprecated in favor of the classes
option, using the ui-droppable-hover
property.
Initialize the droppable with the hoverClass
option specified:
1
2
3
|
|
Get or set the hoverClass
option, after initialization:
1
2
3
4
5
|
|
scope
"default"
accept
option. A draggable with the same scope value as a droppable will be accepted.Initialize the droppable with the scope
option specified:
1
2
3
|
|
Get or set the scope
option, after initialization:
1
2
3
4
5
|
|
tolerance
"intersect"
-
"fit"
: Draggable overlaps the droppable entirely. -
"intersect"
: Draggable overlaps the droppable at least 50% in both directions. -
"pointer"
: Mouse pointer overlaps the droppable. -
"touch"
: Draggable overlaps the droppable any amount.
Initialize the droppable with the tolerance
option specified:
1
2
3
|
|
Get or set the tolerance
option, after initialization:
1
2
3
4
5
|
|
Methods
destroy()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the destroy method:
1
|
|
disable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the disable method:
1
|
|
enable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the enable method:
1
|
|
instance()Returns: Object
Retrieves the droppable's instance object. If the element does not have an associated instance, undefined
is returned.
Unlike other widget methods, instance()
is safe to call on any element after the droppable plugin has loaded.
- This method does not accept any arguments.
Invoke the instance method:
1
|
|
option( optionName )Returns: Object
Gets the value currently associated with the specified optionName
.
Note: For options that have objects as their value, you can get the value of a specific key by using dot notation. For example, "foo.bar"
would get the value of the bar
property on the foo
option.
-
optionNameType: StringThe name of the option to get.
Invoke the method:
1
|
|
option()Returns: PlainObject
- This signature does not accept any arguments.
Invoke the method:
1
|
|
option( optionName, value )Returns: jQuery (plugin only)
Sets the value of the droppable option associated with the specified optionName
.
Note: For options that have objects as their value, you can set the value of just one property by using dot notation for optionName
. For example, "foo.bar"
would update only the bar
property of the foo
option.
-
optionNameType: StringThe name of the option to set.
-
valueType: ObjectA value to set for the option.
Invoke the method:
1
|
|
option( options )Returns: jQuery (plugin only)
-
optionsType: ObjectA map of option-value pairs to set.
Invoke the method:
1
|
|
widget()Returns: jQuery
jQuery
object containing the droppable element.
- This method does not accept any arguments.
Invoke the widget method:
1
|
|
Events
activate( event, ui )Type: dropactivate
-
eventType: Event
-
uiType: Object
-
draggableType: jQueryA jQuery object representing the draggable element.
-
helperType: jQueryA jQuery object representing the helper that is being dragged.
-
positionType: ObjectCurrent CSS position of the draggable helper as
{ top, left }
object. -
offsetType: ObjectCurrent offset position of the draggable helper as
{ top, left }
object.
-
Initialize the droppable with the activate callback specified:
1
2
3
|
|
Bind an event listener to the dropactivate event:
1
|
|
create( event, ui )Type: dropcreate
Note: The ui
object is empty but included for consistency with other events.
Initialize the droppable with the create callback specified:
1
2
3
|
|
Bind an event listener to the dropcreate event:
1
|
|
deactivate( event, ui )Type: dropdeactivate
-
eventType: Event
-
uiType: Object
-
draggableType: jQueryA jQuery object representing the draggable element.
-
helperType: jQueryA jQuery object representing the helper that is being dragged.
-
positionType: ObjectCurrent CSS position of the draggable helper as
{ top, left }
object. -
offsetType: ObjectCurrent offset position of the draggable helper as
{ top, left }
object.
-
Initialize the droppable with the deactivate callback specified:
1
2
3
|
|
Bind an event listener to the dropdeactivate event:
1
|
|
drop( event, ui )Type: drop
tolerance
option).-
eventType: Event
-
uiType: Object
-
draggableType: jQueryA jQuery object representing the draggable element.
-
helperType: jQueryA jQuery object representing the helper that is being dragged.
-
positionType: ObjectCurrent CSS position of the draggable helper as
{ top, left }
object. -
offsetType: ObjectCurrent offset position of the draggable helper as
{ top, left }
object.
-
Initialize the droppable with the drop callback specified:
1
2
3
|
|
Bind an event listener to the drop event:
1
|
|
out( event, ui )Type: dropout
tolerance
option).Note: The ui
object is empty but included for consistency with other events.
Initialize the droppable with the out callback specified:
1
2
3
|
|
Bind an event listener to the dropout event:
1
|
|
over( event, ui )Type: dropover
tolerance
option).-
eventType: Event
-
uiType: Object
-
draggableType: jQueryA jQuery object representing the draggable element.
-
helperType: jQueryA jQuery object representing the helper that is being dragged.
-
positionType: ObjectCurrent CSS position of the draggable helper as
{ top, left }
object. -
offsetType: ObjectCurrent offset position of the draggable helper as
{ top, left }
object.
-
Initialize the droppable with the over callback specified:
1
2
3
|
|
Bind an event listener to the dropover event:
1
|
|
Example:
A pair of draggable and droppable elements.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
|