2
<ul class="UIAPIPlugin-toc">
3
<li><a href="#overview">Overview</a></li>
4
<li><a href="#options">Options</a></li>
5
<li><a href="#events">Events</a></li>
6
<li><a href="#methods">Methods</a></li>
7
<li><a href="#theming">Theming</a></li>
9
<div class="UIAPIPlugin">
10
<h1>jQuery UI Draggable</h1>
12
<h2 class="top-header">Overview</h2>
13
<div id="overview-main">
14
<p>The jQuery UI Draggable plugin makes selected elements draggable by mouse.</p>
15
<p>Draggable elements gets a class of <code>ui-draggable</code>. During drag the element also gets a class of <code>ui-draggable-dragging</code>. If you want not just drag, but drag-and-drop, see the jQuery UI Droppable plugin, which provides a drop target for draggables.</p>
16
<p>All callbacks (start, stop, drag) 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'):</p>
18
<li><b>ui.helper</b> - the jQuery object representing the helper that's being dragged</li>
19
<li><b>ui.position</b> - current position of the helper as { top, left } object, relative to the offset element</li>
20
<li><b>ui.offset</b> - current absolute position of the helper as { top, left } object, relative to page</li>
23
<div id="overview-dependencies">
29
<div id="overview-example">
31
<div id="overview-example" class="example">
32
<ul><li><a href="#demo"><span>Demo</span></a></li><li><a href="#source"><span>View Source</span></a></li></ul>
33
<p><div id="demo" class="tabs-container" rel="170">
34
Initialize a draggable with default options.<br />
36
<pre>$("#draggable").draggable();
38
<p></div><div id="source" class="tabs-container">
40
<pre><!DOCTYPE html>
43
<link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" />
44
<script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
45
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
46
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.draggable.js"></script>
47
<style type="text/css">
48
#draggable { width: 100px; height: 70px; background: silver; }
50
<script type="text/javascript">
51
$(document).ready(function(){
52
$("#draggable").draggable();
56
<body style="font-size:62.5%;">
58
<div id="draggable">Drag me</div>
68
<h2 class="top-header">Options</h2>
69
<ul class="options-list">
71
<li class="option" id="option-addClasses">
72
<div class="option-header">
73
<h3 class="option-name"><a href="#option-addClasses">addClasses</a></h3>
75
<dt class="option-type-label">Type:</dt>
76
<dd class="option-type">Boolean</dd>
78
<dt class="option-default-label">Default:</dt>
79
<dd class="option-default">true</dd>
83
<div class="option-description">
84
<p>If set to false, will prevent the <code>ui-draggable</code> class from being added. This may be desired as a performance optimization when calling <code>.draggable()</code> init on many hundreds of elements.</p>
86
<div class="option-examples">
87
<h4>Code examples</h4>
88
<dl class="option-examples-list">
91
Initialize a draggable with the <code>addClasses</code> option specified.
94
<pre><code>$('.selector').draggable({ addClasses: false });</code></pre>
99
Get or set the <code>addClasses</code> option, after init.
103
var addClasses = $('.selector').draggable('option', 'addClasses');
105
$('.selector').draggable('option', 'addClasses', false);</code></pre>
113
<li class="option" id="option-appendTo">
114
<div class="option-header">
115
<h3 class="option-name"><a href="#option-appendTo">appendTo</a></h3>
117
<dt class="option-type-label">Type:</dt>
118
<dd class="option-type">Element, Selector</dd>
120
<dt class="option-default-label">Default:</dt>
121
<dd class="option-default">'parent'</dd>
125
<div class="option-description">
126
<p>The element passed to or selected by the <code>appendTo</code> option will be used as the draggable helper's container during dragging. By default, the helper is appended to the same container as the draggable.</p>
128
<div class="option-examples">
129
<h4>Code examples</h4>
130
<dl class="option-examples-list">
133
Initialize a draggable with the <code>appendTo</code> option specified.
136
<pre><code>$('.selector').draggable({ appendTo: 'body' });</code></pre>
141
Get or set the <code>appendTo</code> option, after init.
145
var appendTo = $('.selector').draggable('option', 'appendTo');
147
$('.selector').draggable('option', 'appendTo', 'body');</code></pre>
155
<li class="option" id="option-axis">
156
<div class="option-header">
157
<h3 class="option-name"><a href="#option-axis">axis</a></h3>
159
<dt class="option-type-label">Type:</dt>
160
<dd class="option-type">String</dd>
162
<dt class="option-default-label">Default:</dt>
163
<dd class="option-default">false</dd>
167
<div class="option-description">
168
<p>Constrains dragging to either the horizontal (x) or vertical (y) axis. Possible values: 'x', 'y'.</p>
170
<div class="option-examples">
171
<h4>Code examples</h4>
172
<dl class="option-examples-list">
175
Initialize a draggable with the <code>axis</code> option specified.
178
<pre><code>$('.selector').draggable({ axis: 'x' });</code></pre>
183
Get or set the <code>axis</code> option, after init.
187
var axis = $('.selector').draggable('option', 'axis');
189
$('.selector').draggable('option', 'axis', 'x');</code></pre>
197
<li class="option" id="option-cancel">
198
<div class="option-header">
199
<h3 class="option-name"><a href="#option-cancel">cancel</a></h3>
201
<dt class="option-type-label">Type:</dt>
202
<dd class="option-type">Selector</dd>
204
<dt class="option-default-label">Default:</dt>
205
<dd class="option-default">':input,option'</dd>
209
<div class="option-description">
210
<p>Prevents dragging from starting on specified elements.</p>
212
<div class="option-examples">
213
<h4>Code examples</h4>
214
<dl class="option-examples-list">
217
Initialize a draggable with the <code>cancel</code> option specified.
220
<pre><code>$('.selector').draggable({ cancel: 'button' });</code></pre>
225
Get or set the <code>cancel</code> option, after init.
229
var cancel = $('.selector').draggable('option', 'cancel');
231
$('.selector').draggable('option', 'cancel', 'button');</code></pre>
239
<li class="option" id="option-connectToSortable">
240
<div class="option-header">
241
<h3 class="option-name"><a href="#option-connectToSortable">connectToSortable</a></h3>
243
<dt class="option-type-label">Type:</dt>
244
<dd class="option-type">Selector</dd>
246
<dt class="option-default-label">Default:</dt>
247
<dd class="option-default">false</dd>
251
<div class="option-description">
252
<p>Allows the draggable to be dropped onto the specified sortables. If this option is used (<code>helper</code> must be set to 'clone' in order to work flawlessly), a draggable can be dropped onto a sortable list and then becomes part of it.
253
</p><p>Note: Specifying this option as an array of selectors has been removed.</p>
255
<div class="option-examples">
256
<h4>Code examples</h4>
257
<dl class="option-examples-list">
260
Initialize a draggable with the <code>connectToSortable</code> option specified.
263
<pre><code>$('.selector').draggable({ connectToSortable: 'ul#myList' });</code></pre>
268
Get or set the <code>connectToSortable</code> option, after init.
272
var connectToSortable = $('.selector').draggable('option', 'connectToSortable');
274
$('.selector').draggable('option', 'connectToSortable', 'ul#myList');</code></pre>
282
<li class="option" id="option-containment">
283
<div class="option-header">
284
<h3 class="option-name"><a href="#option-containment">containment</a></h3>
286
<dt class="option-type-label">Type:</dt>
287
<dd class="option-type">Selector, Element, String, Array</dd>
289
<dt class="option-default-label">Default:</dt>
290
<dd class="option-default">false</dd>
294
<div class="option-description">
295
<p>Constrains dragging to within the bounds of the specified element or region. Possible string values: 'parent', 'document', 'window', [x1, y1, x2, y2].</p>
297
<div class="option-examples">
298
<h4>Code examples</h4>
299
<dl class="option-examples-list">
302
Initialize a draggable with the <code>containment</code> option specified.
305
<pre><code>$('.selector').draggable({ containment: 'parent' });</code></pre>
310
Get or set the <code>containment</code> option, after init.
314
var containment = $('.selector').draggable('option', 'containment');
316
$('.selector').draggable('option', 'containment', 'parent');</code></pre>
324
<li class="option" id="option-cursor">
325
<div class="option-header">
326
<h3 class="option-name"><a href="#option-cursor">cursor</a></h3>
328
<dt class="option-type-label">Type:</dt>
329
<dd class="option-type">String</dd>
331
<dt class="option-default-label">Default:</dt>
332
<dd class="option-default">'auto'</dd>
336
<div class="option-description">
337
<p>The css cursor during the drag operation.</p>
339
<div class="option-examples">
340
<h4>Code examples</h4>
341
<dl class="option-examples-list">
344
Initialize a draggable with the <code>cursor</code> option specified.
347
<pre><code>$('.selector').draggable({ cursor: 'crosshair' });</code></pre>
352
Get or set the <code>cursor</code> option, after init.
356
var cursor = $('.selector').draggable('option', 'cursor');
358
$('.selector').draggable('option', 'cursor', 'crosshair');</code></pre>
366
<li class="option" id="option-cursorAt">
367
<div class="option-header">
368
<h3 class="option-name"><a href="#option-cursorAt">cursorAt</a></h3>
370
<dt class="option-type-label">Type:</dt>
371
<dd class="option-type">Object</dd>
373
<dt class="option-default-label">Default:</dt>
374
<dd class="option-default">false</dd>
378
<div class="option-description">
379
<p>Moves the dragging helper so the cursor always appears to drag from the same position. Coordinates can be given as a hash using a combination of one or two keys: <code>{ top, left, right, bottom }</code>.</p>
381
<div class="option-examples">
382
<h4>Code examples</h4>
383
<dl class="option-examples-list">
386
Initialize a draggable with the <code>cursorAt</code> option specified.
389
<pre><code>$('.selector').draggable({ cursorAt: { left: 5 } });</code></pre>
394
Get or set the <code>cursorAt</code> option, after init.
398
var cursorAt = $('.selector').draggable('option', 'cursorAt');
400
$('.selector').draggable('option', 'cursorAt', { left: 5 });</code></pre>
408
<li class="option" id="option-delay">
409
<div class="option-header">
410
<h3 class="option-name"><a href="#option-delay">delay</a></h3>
412
<dt class="option-type-label">Type:</dt>
413
<dd class="option-type">Integer</dd>
415
<dt class="option-default-label">Default:</dt>
416
<dd class="option-default">0</dd>
420
<div class="option-description">
421
<p>Time in milliseconds after mousedown until dragging should start. This option can be used to prevent unwanted drags when clicking on an element.</p>
423
<div class="option-examples">
424
<h4>Code examples</h4>
425
<dl class="option-examples-list">
428
Initialize a draggable with the <code>delay</code> option specified.
431
<pre><code>$('.selector').draggable({ delay: 500 });</code></pre>
436
Get or set the <code>delay</code> option, after init.
440
var delay = $('.selector').draggable('option', 'delay');
442
$('.selector').draggable('option', 'delay', 500);</code></pre>
450
<li class="option" id="option-distance">
451
<div class="option-header">
452
<h3 class="option-name"><a href="#option-distance">distance</a></h3>
454
<dt class="option-type-label">Type:</dt>
455
<dd class="option-type">Integer</dd>
457
<dt class="option-default-label">Default:</dt>
458
<dd class="option-default">1</dd>
462
<div class="option-description">
463
<p>Distance in pixels after mousedown the mouse must move before dragging should start. This option can be used to prevent unwanted drags when clicking on an element.</p>
465
<div class="option-examples">
466
<h4>Code examples</h4>
467
<dl class="option-examples-list">
470
Initialize a draggable with the <code>distance</code> option specified.
473
<pre><code>$('.selector').draggable({ distance: 30 });</code></pre>
478
Get or set the <code>distance</code> option, after init.
482
var distance = $('.selector').draggable('option', 'distance');
484
$('.selector').draggable('option', 'distance', 30);</code></pre>
492
<li class="option" id="option-grid">
493
<div class="option-header">
494
<h3 class="option-name"><a href="#option-grid">grid</a></h3>
496
<dt class="option-type-label">Type:</dt>
497
<dd class="option-type">Array</dd>
499
<dt class="option-default-label">Default:</dt>
500
<dd class="option-default">false</dd>
504
<div class="option-description">
505
<p>Snaps the dragging helper to a grid, every x and y pixels. Array values: [x, y]</p>
507
<div class="option-examples">
508
<h4>Code examples</h4>
509
<dl class="option-examples-list">
512
Initialize a draggable with the <code>grid</code> option specified.
515
<pre><code>$('.selector').draggable({ grid: [50, 20] });</code></pre>
520
Get or set the <code>grid</code> option, after init.
524
var grid = $('.selector').draggable('option', 'grid');
526
$('.selector').draggable('option', 'grid', [50, 20]);</code></pre>
534
<li class="option" id="option-handle">
535
<div class="option-header">
536
<h3 class="option-name"><a href="#option-handle">handle</a></h3>
538
<dt class="option-type-label">Type:</dt>
539
<dd class="option-type">Element, Selector</dd>
541
<dt class="option-default-label">Default:</dt>
542
<dd class="option-default">false</dd>
546
<div class="option-description">
547
<p>If specified, restricts drag start click to the specified element(s).</p>
549
<div class="option-examples">
550
<h4>Code examples</h4>
551
<dl class="option-examples-list">
554
Initialize a draggable with the <code>handle</code> option specified.
557
<pre><code>$('.selector').draggable({ handle: 'h2' });</code></pre>
562
Get or set the <code>handle</code> option, after init.
566
var handle = $('.selector').draggable('option', 'handle');
568
$('.selector').draggable('option', 'handle', 'h2');</code></pre>
576
<li class="option" id="option-helper">
577
<div class="option-header">
578
<h3 class="option-name"><a href="#option-helper">helper</a></h3>
580
<dt class="option-type-label">Type:</dt>
581
<dd class="option-type">String, Function</dd>
583
<dt class="option-default-label">Default:</dt>
584
<dd class="option-default">'original'</dd>
588
<div class="option-description">
589
<p>Allows for a helper element to be used for dragging display. Possible values: 'original', 'clone', Function. If a function is specified, it must return a DOMElement.</p>
591
<div class="option-examples">
592
<h4>Code examples</h4>
593
<dl class="option-examples-list">
596
Initialize a draggable with the <code>helper</code> option specified.
599
<pre><code>$('.selector').draggable({ helper: 'clone' });</code></pre>
604
Get or set the <code>helper</code> option, after init.
608
var helper = $('.selector').draggable('option', 'helper');
610
$('.selector').draggable('option', 'helper', 'clone');</code></pre>
618
<li class="option" id="option-iframeFix">
619
<div class="option-header">
620
<h3 class="option-name"><a href="#option-iframeFix">iframeFix</a></h3>
622
<dt class="option-type-label">Type:</dt>
623
<dd class="option-type">Boolean, Selector</dd>
625
<dt class="option-default-label">Default:</dt>
626
<dd class="option-default">false</dd>
630
<div class="option-description">
631
<p>Prevent iframes from capturing the mousemove events during a drag. Useful in combination with cursorAt, or in any case, if the mouse cursor is not over the helper. If set to true, transparent overlays will be placed over all iframes on the page. If a selector is supplied, the matched iframes will have an overlay placed over them.</p>
633
<div class="option-examples">
634
<h4>Code examples</h4>
635
<dl class="option-examples-list">
638
Initialize a draggable with the <code>iframeFix</code> option specified.
641
<pre><code>$('.selector').draggable({ iframeFix: true });</code></pre>
646
Get or set the <code>iframeFix</code> option, after init.
650
var iframeFix = $('.selector').draggable('option', 'iframeFix');
652
$('.selector').draggable('option', 'iframeFix', true);</code></pre>
660
<li class="option" id="option-opacity">
661
<div class="option-header">
662
<h3 class="option-name"><a href="#option-opacity">opacity</a></h3>
664
<dt class="option-type-label">Type:</dt>
665
<dd class="option-type">Float</dd>
667
<dt class="option-default-label">Default:</dt>
668
<dd class="option-default">false</dd>
672
<div class="option-description">
673
<p>Opacity for the helper while being dragged.</p>
675
<div class="option-examples">
676
<h4>Code examples</h4>
677
<dl class="option-examples-list">
680
Initialize a draggable with the <code>opacity</code> option specified.
683
<pre><code>$('.selector').draggable({ opacity: 0.35 });</code></pre>
688
Get or set the <code>opacity</code> option, after init.
692
var opacity = $('.selector').draggable('option', 'opacity');
694
$('.selector').draggable('option', 'opacity', 0.35);</code></pre>
702
<li class="option" id="option-refreshPositions">
703
<div class="option-header">
704
<h3 class="option-name"><a href="#option-refreshPositions">refreshPositions</a></h3>
706
<dt class="option-type-label">Type:</dt>
707
<dd class="option-type">Boolean</dd>
709
<dt class="option-default-label">Default:</dt>
710
<dd class="option-default">false</dd>
714
<div class="option-description">
715
<p>If set to true, all droppable positions are calculated on every mousemove. Caution: This solves issues on highly dynamic pages, but dramatically decreases performance.</p>
717
<div class="option-examples">
718
<h4>Code examples</h4>
719
<dl class="option-examples-list">
722
Initialize a draggable with the <code>refreshPositions</code> option specified.
725
<pre><code>$('.selector').draggable({ refreshPositions: true });</code></pre>
730
Get or set the <code>refreshPositions</code> option, after init.
734
var refreshPositions = $('.selector').draggable('option', 'refreshPositions');
736
$('.selector').draggable('option', 'refreshPositions', true);</code></pre>
744
<li class="option" id="option-revert">
745
<div class="option-header">
746
<h3 class="option-name"><a href="#option-revert">revert</a></h3>
748
<dt class="option-type-label">Type:</dt>
749
<dd class="option-type">Boolean, String</dd>
751
<dt class="option-default-label">Default:</dt>
752
<dd class="option-default">false</dd>
756
<div class="option-description">
757
<p>If set to true, the element will return to its start position when dragging stops. Possible string values: 'valid', 'invalid'. 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.</p>
759
<div class="option-examples">
760
<h4>Code examples</h4>
761
<dl class="option-examples-list">
764
Initialize a draggable with the <code>revert</code> option specified.
767
<pre><code>$('.selector').draggable({ revert: true });</code></pre>
772
Get or set the <code>revert</code> option, after init.
776
var revert = $('.selector').draggable('option', 'revert');
778
$('.selector').draggable('option', 'revert', true);</code></pre>
786
<li class="option" id="option-revertDuration">
787
<div class="option-header">
788
<h3 class="option-name"><a href="#option-revertDuration">revertDuration</a></h3>
790
<dt class="option-type-label">Type:</dt>
791
<dd class="option-type">Integer</dd>
793
<dt class="option-default-label">Default:</dt>
794
<dd class="option-default">500</dd>
798
<div class="option-description">
799
<p>The duration of the revert animation, in milliseconds. Ignored if revert is false.</p>
801
<div class="option-examples">
802
<h4>Code examples</h4>
803
<dl class="option-examples-list">
806
Initialize a draggable with the <code>revertDuration</code> option specified.
809
<pre><code>$('.selector').draggable({ revertDuration: 1000 });</code></pre>
814
Get or set the <code>revertDuration</code> option, after init.
818
var revertDuration = $('.selector').draggable('option', 'revertDuration');
820
$('.selector').draggable('option', 'revertDuration', 1000);</code></pre>
828
<li class="option" id="option-scope">
829
<div class="option-header">
830
<h3 class="option-name"><a href="#option-scope">scope</a></h3>
832
<dt class="option-type-label">Type:</dt>
833
<dd class="option-type">String</dd>
835
<dt class="option-default-label">Default:</dt>
836
<dd class="option-default">'default'</dd>
840
<div class="option-description">
841
<p>Used to group sets of draggable and droppable items, in addition to droppable's accept option. A draggable with the same scope value as a droppable will be accepted by the droppable.</p>
843
<div class="option-examples">
844
<h4>Code examples</h4>
845
<dl class="option-examples-list">
848
Initialize a draggable with the <code>scope</code> option specified.
851
<pre><code>$('.selector').draggable({ scope: 'tasks' });</code></pre>
856
Get or set the <code>scope</code> option, after init.
860
var scope = $('.selector').draggable('option', 'scope');
862
$('.selector').draggable('option', 'scope', 'tasks');</code></pre>
870
<li class="option" id="option-scroll">
871
<div class="option-header">
872
<h3 class="option-name"><a href="#option-scroll">scroll</a></h3>
874
<dt class="option-type-label">Type:</dt>
875
<dd class="option-type">Boolean</dd>
877
<dt class="option-default-label">Default:</dt>
878
<dd class="option-default">true</dd>
882
<div class="option-description">
883
<p>If set to true, container auto-scrolls while dragging.</p>
885
<div class="option-examples">
886
<h4>Code examples</h4>
887
<dl class="option-examples-list">
890
Initialize a draggable with the <code>scroll</code> option specified.
893
<pre><code>$('.selector').draggable({ scroll: false });</code></pre>
898
Get or set the <code>scroll</code> option, after init.
902
var scroll = $('.selector').draggable('option', 'scroll');
904
$('.selector').draggable('option', 'scroll', false);</code></pre>
912
<li class="option" id="option-scrollSensitivity">
913
<div class="option-header">
914
<h3 class="option-name"><a href="#option-scrollSensitivity">scrollSensitivity</a></h3>
916
<dt class="option-type-label">Type:</dt>
917
<dd class="option-type">Integer</dd>
919
<dt class="option-default-label">Default:</dt>
920
<dd class="option-default">20</dd>
924
<div class="option-description">
925
<p>Distance in pixels from the edge of the viewport after which the viewport should scroll. Distance is relative to pointer, not the draggable.</p>
927
<div class="option-examples">
928
<h4>Code examples</h4>
929
<dl class="option-examples-list">
932
Initialize a draggable with the <code>scrollSensitivity</code> option specified.
935
<pre><code>$('.selector').draggable({ scrollSensitivity: 40 });</code></pre>
940
Get or set the <code>scrollSensitivity</code> option, after init.
944
var scrollSensitivity = $('.selector').draggable('option', 'scrollSensitivity');
946
$('.selector').draggable('option', 'scrollSensitivity', 40);</code></pre>
954
<li class="option" id="option-scrollSpeed">
955
<div class="option-header">
956
<h3 class="option-name"><a href="#option-scrollSpeed">scrollSpeed</a></h3>
958
<dt class="option-type-label">Type:</dt>
959
<dd class="option-type">Integer</dd>
961
<dt class="option-default-label">Default:</dt>
962
<dd class="option-default">20</dd>
966
<div class="option-description">
967
<p>The speed at which the window should scroll once the mouse pointer gets within the <code>scrollSensitivity</code> distance.</p>
969
<div class="option-examples">
970
<h4>Code examples</h4>
971
<dl class="option-examples-list">
974
Initialize a draggable with the <code>scrollSpeed</code> option specified.
977
<pre><code>$('.selector').draggable({ scrollSpeed: 40 });</code></pre>
982
Get or set the <code>scrollSpeed</code> option, after init.
986
var scrollSpeed = $('.selector').draggable('option', 'scrollSpeed');
988
$('.selector').draggable('option', 'scrollSpeed', 40);</code></pre>
996
<li class="option" id="option-snap">
997
<div class="option-header">
998
<h3 class="option-name"><a href="#option-snap">snap</a></h3>
1000
<dt class="option-type-label">Type:</dt>
1001
<dd class="option-type">Boolean, Selector</dd>
1003
<dt class="option-default-label">Default:</dt>
1004
<dd class="option-default">false</dd>
1008
<div class="option-description">
1009
<p>If set to a selector or to true (equivalent to '.ui-draggable'), the draggable will snap to the edges of the selected elements when near an edge of the element.</p>
1011
<div class="option-examples">
1012
<h4>Code examples</h4>
1013
<dl class="option-examples-list">
1016
Initialize a draggable with the <code>snap</code> option specified.
1019
<pre><code>$('.selector').draggable({ snap: true });</code></pre>
1024
Get or set the <code>snap</code> option, after init.
1028
var snap = $('.selector').draggable('option', 'snap');
1030
$('.selector').draggable('option', 'snap', true);</code></pre>
1038
<li class="option" id="option-snapMode">
1039
<div class="option-header">
1040
<h3 class="option-name"><a href="#option-snapMode">snapMode</a></h3>
1042
<dt class="option-type-label">Type:</dt>
1043
<dd class="option-type">String</dd>
1045
<dt class="option-default-label">Default:</dt>
1046
<dd class="option-default">'both'</dd>
1050
<div class="option-description">
1051
<p>Determines which edges of snap elements the draggable will snap to. Ignored if snap is false. Possible values: 'inner', 'outer', 'both'</p>
1053
<div class="option-examples">
1054
<h4>Code examples</h4>
1055
<dl class="option-examples-list">
1058
Initialize a draggable with the <code>snapMode</code> option specified.
1061
<pre><code>$('.selector').draggable({ snapMode: 'outer' });</code></pre>
1066
Get or set the <code>snapMode</code> option, after init.
1070
var snapMode = $('.selector').draggable('option', 'snapMode');
1072
$('.selector').draggable('option', 'snapMode', 'outer');</code></pre>
1080
<li class="option" id="option-snapTolerance">
1081
<div class="option-header">
1082
<h3 class="option-name"><a href="#option-snapTolerance">snapTolerance</a></h3>
1084
<dt class="option-type-label">Type:</dt>
1085
<dd class="option-type">Integer</dd>
1087
<dt class="option-default-label">Default:</dt>
1088
<dd class="option-default">20</dd>
1092
<div class="option-description">
1093
<p>The distance in pixels from the snap element edges at which snapping should occur. Ignored if snap is false.</p>
1095
<div class="option-examples">
1096
<h4>Code examples</h4>
1097
<dl class="option-examples-list">
1100
Initialize a draggable with the <code>snapTolerance</code> option specified.
1103
<pre><code>$('.selector').draggable({ snapTolerance: 40 });</code></pre>
1108
Get or set the <code>snapTolerance</code> option, after init.
1112
var snapTolerance = $('.selector').draggable('option', 'snapTolerance');
1114
$('.selector').draggable('option', 'snapTolerance', 40);</code></pre>
1122
<li class="option" id="option-stack">
1123
<div class="option-header">
1124
<h3 class="option-name"><a href="#option-stack">stack</a></h3>
1126
<dt class="option-type-label">Type:</dt>
1127
<dd class="option-type">Object</dd>
1129
<dt class="option-default-label">Default:</dt>
1130
<dd class="option-default">false</dd>
1134
<div class="option-description">
1135
<p>Controls the z-Index of the defined group (key 'group' in the hash, accepts jQuery selector) automatically, always brings to front the dragged item. Very useful in things like window managers. Optionally, a 'min' key can be set, so the zIndex cannot go below that value.</p>
1137
<div class="option-examples">
1138
<h4>Code examples</h4>
1139
<dl class="option-examples-list">
1142
Initialize a draggable with the <code>stack</code> option specified.
1145
<pre><code>$('.selector').draggable({ stack: { group: 'products', min: 50 } });</code></pre>
1150
Get or set the <code>stack</code> option, after init.
1154
var stack = $('.selector').draggable('option', 'stack');
1156
$('.selector').draggable('option', 'stack', { group: 'products', min: 50 });</code></pre>
1164
<li class="option" id="option-zIndex">
1165
<div class="option-header">
1166
<h3 class="option-name"><a href="#option-zIndex">zIndex</a></h3>
1168
<dt class="option-type-label">Type:</dt>
1169
<dd class="option-type">Integer</dd>
1171
<dt class="option-default-label">Default:</dt>
1172
<dd class="option-default">false</dd>
1176
<div class="option-description">
1177
<p>z-index for the helper while being dragged.</p>
1179
<div class="option-examples">
1180
<h4>Code examples</h4>
1181
<dl class="option-examples-list">
1184
Initialize a draggable with the <code>zIndex</code> option specified.
1187
<pre><code>$('.selector').draggable({ zIndex: 2700 });</code></pre>
1192
Get or set the <code>zIndex</code> option, after init.
1196
var zIndex = $('.selector').draggable('option', 'zIndex');
1198
$('.selector').draggable('option', 'zIndex', 2700);</code></pre>
1208
<h2 class="top-header">Events</h2>
1209
<ul class="events-list">
1211
<li class="event" id="event-start">
1212
<div class="event-header">
1213
<h3 class="event-name"><a href="#event-start">start</a></h3>
1215
<dt class="event-type-label">Type:</dt>
1216
<dd class="event-type">dragstart</dd>
1219
<div class="event-description">
1220
<p>This event is triggered when dragging starts.</p>
1222
<div class="event-examples">
1223
<h4>Code examples</h4>
1224
<dl class="event-examples-list">
1227
Supply a callback function to handle the <code>start</code> event as an init option.
1230
<pre><code>$('.selector').draggable({
1231
start: function(event, ui) { ... }
1237
Bind to the <code>start</code> event by type: <code>dragstart</code>.
1240
<pre><code>$('.selector').bind('dragstart', function(event, ui) {
1250
<li class="event" id="event-drag">
1251
<div class="event-header">
1252
<h3 class="event-name"><a href="#event-drag">drag</a></h3>
1254
<dt class="event-type-label">Type:</dt>
1255
<dd class="event-type">drag</dd>
1258
<div class="event-description">
1259
<p>This event is triggered when the mouse is moved during the dragging.</p>
1261
<div class="event-examples">
1262
<h4>Code examples</h4>
1263
<dl class="event-examples-list">
1266
Supply a callback function to handle the <code>drag</code> event as an init option.
1269
<pre><code>$('.selector').draggable({
1270
drag: function(event, ui) { ... }
1276
Bind to the <code>drag</code> event by type: <code>drag</code>.
1279
<pre><code>$('.selector').bind('drag', function(event, ui) {
1289
<li class="event" id="event-stop">
1290
<div class="event-header">
1291
<h3 class="event-name"><a href="#event-stop">stop</a></h3>
1293
<dt class="event-type-label">Type:</dt>
1294
<dd class="event-type">dragstop</dd>
1297
<div class="event-description">
1298
<p>This event is triggered when dragging stops.</p>
1300
<div class="event-examples">
1301
<h4>Code examples</h4>
1302
<dl class="event-examples-list">
1305
Supply a callback function to handle the <code>stop</code> event as an init option.
1308
<pre><code>$('.selector').draggable({
1309
stop: function(event, ui) { ... }
1315
Bind to the <code>stop</code> event by type: <code>dragstop</code>.
1318
<pre><code>$('.selector').bind('dragstop', function(event, ui) {
1330
<h2 class="top-header">Methods</h2>
1331
<ul class="methods-list">
1333
<li class="method" id="method-destroy">
1334
<div class="method-header">
1335
<h3 class="method-name"><a href="#method-destroy">destroy</a></h3>
1337
<dt class="method-signature-label">Signature:</dt>
1338
<dd class="method-signature">.draggable( 'destroy'
1349
<div class="method-description">
1350
<p>Remove the draggable functionality completely. This will return the element back to its pre-init state.</p>
1355
<li class="method" id="method-disable">
1356
<div class="method-header">
1357
<h3 class="method-name"><a href="#method-disable">disable</a></h3>
1359
<dt class="method-signature-label">Signature:</dt>
1360
<dd class="method-signature">.draggable( 'disable'
1371
<div class="method-description">
1372
<p>Disable the draggable.</p>
1377
<li class="method" id="method-enable">
1378
<div class="method-header">
1379
<h3 class="method-name"><a href="#method-enable">enable</a></h3>
1381
<dt class="method-signature-label">Signature:</dt>
1382
<dd class="method-signature">.draggable( 'enable'
1393
<div class="method-description">
1394
<p>Enable the draggable.</p>
1399
<li class="method" id="method-option">
1400
<div class="method-header">
1401
<h3 class="method-name"><a href="#method-option">option</a></h3>
1403
<dt class="method-signature-label">Signature:</dt>
1404
<dd class="method-signature">.draggable( 'option'
1408
, <span class="optional">[</span>value<span class="optional">] </span>
1415
<div class="method-description">
1416
<p>Get or set any draggable option. If no value is specified, will act as a getter.</p>
1424
<h2 class="top-header">Theming</h2>
1425
<p>The jQuery UI Draggable 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.
1427
<p>If a deeper level of customization is needed, there are widget-specific classes referenced within the ui.draggable.css stylesheet that can be modified. These classes are highlighed in bold below.
1430
<h3>Sample markup with jQuery UI CSS Framework classes</h3>
1431
<div class="<strong>ui-draggable</strong>"></div>
1432
<p class="theme-note">
1434
Note: This is a sample of markup generated by the draggable plugin, not markup you should use to create a draggable. The only markup needed for that is <div></div>.
1442
Pre-expand include size: 55070 bytes
1443
Post-expand include size: 98892 bytes
1444
Template argument size: 56660 bytes
1445
Maximum: 2097152 bytes
1448
<!-- Saved in parser cache with key jqdocs_docs:pcache:idhash:3174-1!1!0!!en!2 and timestamp 20090319021835 -->