Draggable Widgetversion added: 1.0
Description: Allow elements to be moved using the mouse.
Make the selected elements draggable by mouse. If you want not just drag, but drag & drop, see the jQuery UI Droppable plugin, which provides a drop target for draggables.
Options
addClasses
true
false
, will prevent the ui-draggable
class from being added. This may be desired as a performance optimization when calling .draggable()
on hundreds of elements.appendTo
"parent"
- jQuery: A jQuery object containing the element to append the helper to.
- Element: The element to append the helper to.
- Selector: A selector specifying which element to append the helper to.
-
String: The string
"parent"
will cause the helper to be a sibling of the draggable.
axis
false
"x"
, "y"
.cancel
"input,textarea,button,select,option"
connectToSortable
false
helper
option must be set to "clone"
in order to work flawlessly. Requires the jQuery UI Sortable plugin to be included.containment
false
- Selector: The draggable element will be contained to the bounding box of the first element found by the selector. If no element is found, no containment will be set.
- Element: The draggable element will be contained to the bounding box of this element.
-
String: Possible values:
"parent"
,"document"
,"window"
. -
Array: An array defining a bounding box in the form
[ x1, y1, x2, y2 ]
.
cursorAt
false
{ top, left, right, bottom }
.delay
0
distance
1
grid
false
[ x, y ]
.handle
false
helper
"original"
-
String: If set to
"clone"
, then the element will be cloned and the clone will be dragged. - Function: A function that will return a DOMElement to use while dragging.
iframeFix
false
cursorAt
option, or in any case where the mouse cursor may not be over the helper.-
Boolean: When set to
true
, transparent overlays will be placed over all iframes on the page. - Selector: Any iframes matching the selector will be covered by transparent overlays.
refreshPositions
false
true
, all droppable positions are calculated on every mousemove.
Caution: This solves issues on highly dynamic pages, but dramatically decreases performance.
revert
false
-
Boolean: If set to
true
the element will always revert. -
String: If set to
"invalid"
, revert will only occur if the draggable has not been dropped on a droppable. For"valid"
, it's the other way around.
revertDuration
500
revert
option is false
.scope
"default"
accept
option. A draggable with the same scope
value as a droppable will be accepted by the droppable.scrollSensitivity
20
scroll
option is false
.scrollSpeed
20
scrollSensitivity
distance. Ignored if the scroll
option is false
.snap
false
-
Boolean: When set to
true
, the element will snap to all other draggable elements. - Selector: A selector specifying which elements to snap to.
snapMode
"both"
snap
option is false
. Possible values: "inner"
, "outer"
, "both"
.snapTolerance
20
snap
option is false
.stack
false
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
|
|
option( optionName )Returns: Object
optionName
.-
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)
optionName
.-
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 draggable element.
- This method does not accept any arguments.
Invoke the widget method:
1
|
|
Events
create( event, ui )Type: draggablecreate
Note: The ui
object is empty but included for consistency with other events.
Initialize the draggable with the create callback specified:
1
2
3
|
|
Bind an event listener to the draggablecreate event:
1
|
|
drag( event, ui )Type: draggabledrag
Initialize the draggable with the drag callback specified:
1
2
3
|
|
Bind an event listener to the draggabledrag event:
1
|
|
start( event, ui )Type: draggablestart
Initialize the draggable with the start callback specified:
1
2
3
|
|
Bind an event listener to the draggablestart event:
1
|
|
stop( event, ui )Type: draggablestop
Initialize the draggable with the stop callback specified:
1
2
3
|
|
Bind an event listener to the draggablestop event:
1
|
|
Example:
A simple jQuery UI Draggable
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
|
|