Draggable
Override defaults with $.fn.draggable.defaults.
Usage Example
Create a draggable element from markup.
- <divid="dd"class="easyui-draggable"data-options="handle:'#title'"style="width:100px;height:100px;">
- <divid="title"style="background:#ccc;">title</div>
- </div>
Create a draggable element using javascript.
- <divid="dd"style="width:100px;height:100px;">
- <divid="title"style="background:#ccc;">title</div>
- </div>
- $('#dd').draggable({
- handle:'#title'
- });
Properties
Name | Type | Description | Default | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
proxy | null或string(比如'clone')或function | A proxy element to be used when dragging, when set to 'clone', a clone element is used as proxy. If a function is specified, it must return a jQuery object.
The example below shows how to create a simple proxy object. //1.默认是null
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Basic Draggable - jQuery EasyUI Demo</title> <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> <link rel="stylesheet" type="text/css" href="../demo.css"> <script type="text/javascript" src="../../jquery.min.js"></script> <script type="text/javascript" src="../../jquery.easyui.min.js"></script> <script> $(function(){ //从此以后,光标都是文本光标了 //$.fn.draggable.defaults.cursor = 'text'; $('#dd').draggable({ proxy : function(source){ //console.log(source); var p = $('<div style="border:1px solid #ccc;height:'+ source.style.height + ';'+source.style.width+'"></div>'); //console.log(p.html($(source).html())); p.html($(source).html()).appendTo('body'); return p; } }); }); </script> </head> <body> <div id="dd" style="100px;height:100px;background:green"> wosout </div> </body> </html> |
null | ||||||||||||||||||||||||||||||||||||
revert | boolean | If set to true, the element will return to its start position when dragging stops. | false | ||||||||||||||||||||||||||||||||||||
cursor | string |
The css cursor when dragging. 可能的值
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Basic Draggable - jQuery EasyUI Demo</title> 6 <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"> 7 <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> 8 <link rel="stylesheet" type="text/css" href="../demo.css"> 9 <script type="text/javascript" src="../../jquery.min.js"></script> 10 <script type="text/javascript" src="../../jquery.easyui.min.js"></script> 11 12 <script> 13 $(function(){ 14 $('#dd').draggable({ 15 cursor:'wait',//光标变成等待 16 handle:'#title' //拖动标题div时 17 }); 18 }); 19 </script> 20 </head> 21 <body> 22 <div id="dd" style="100px;height:100px;"> 23 <div id="title" style="background:#ccc;">title</div> 24 <div id="content" style="80px;height:80px;background:red"></div> 25 </div> 26 </body> 27 </html> |
move | ||||||||||||||||||||||||||||||||||||
deltaX | number | The dragged element position x corresponding to current cursor | null | ||||||||||||||||||||||||||||||||||||
deltaY | number | The dragged element position y corresponding to current cursor | null | ||||||||||||||||||||||||||||||||||||
handle | selector | The handle that start the draggable. | null | ||||||||||||||||||||||||||||||||||||
disabled | boolean | True to stop draggable. | false | ||||||||||||||||||||||||||||||||||||
edge | number | The drag width in which can start draggable. | 0 | ||||||||||||||||||||||||||||||||||||
axis | string | Defines the axis which the dragged elements moves on, available value is 'v' or 'h', when set to null will move across 'v' and 'h' direction. | null | ||||||||||||||||||||||||||||||||||||
delay | number | Defines the delay time in milliseconds to start a drag operation. | 100 |
Events
Name | Parameters | Description |
---|---|---|
onBeforeDrag | e | Fires before dragging, return false to cancel this dragging. |
onStartDrag | e | Fires when the target object start dragging. |
onDrag | e | Fires during dragging. Return false will not do dragging actually. |
onStopDrag | e | Fires when the dragging stops. |
Methods
Name | Parameter | Description |
---|---|---|
options | none | Return the options property. |
proxy | none | Return the drag proxy if the proxy property is setted. |
enable | none | Enable the drag action. |
disable | none | Disable the drag action. |