ejDraggable
12 Dec 20189 minutes to read
Plugin to make any DOM element draggable.
Syntax
$(element).ejDraggable()
Example
<div id="draggable"/>
<script>
// Create draggable
$('#draggable').ejDraggable();
</script>
Requires
-
module:jQuery
-
module:ej.core
-
module:ej.draggable
Members
clone boolean
If clone is specified.
Default Value
- false
Example
//To set clone API value during initialization
$("#draggable").ejDraggable({ clone: true });
//Get or set the clone API, after initialization:
//Gets the clone value
$("#draggable").ejDraggable('option', 'clone');
cursorAt object
Sets the offset of the dragging helper relative to the mouse cursor.
Default Value
- { top: -1, left: -2 }
Example
//To set cursorAt API value during initialization
$("#draggable").ejDraggable({ cursorAt: { top: 1, left: -2 } });
//Get or set the cursorAt API, after initialization:
//Gets the cursorAt value
$("#draggable").ejDraggable('option', 'cursorAt');
distance number
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.
Default Value
- 1
Example
//To set distance API value during initialization
$("#draggable").ejDraggable({ distance: 1 });
//Get or set the distance API, after initialization:
//Gets the distance value
$("#draggable").ejDraggable('option', 'distance');
dragArea boolean
The drag area is used to restrict the dragging element bounds.Specify the id of the container within which the element should be dragged.
Default Value
- null
Example
//To set dragArea API value during initialization
$("#draggable").ejDraggable({ dragArea:"#container"});
//Get or set the dragArea API, after initialization:
//Gets the dragArea value
$("#draggable").ejDraggable('option', 'dragArea');
handle string
If specified, restricts drag start click to the specified element(s).
Default Value
- null
Example
//To set handle API value during initialization
$("#draggable").ejDraggable({ handle: null });
//Get or set the handle API, after initialization:
//Gets the handle value
$("#draggable").ejDraggable('option', 'handle');
scope string
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.
Default Value
- ‘default’
Example
//To set scope API value during initialization
$("#draggable").ejDraggable({ scope: 'default' });
//Get or set the scope API, after initialization:
//Gets the scope value
$("#draggable").ejDraggable('option', 'scope');
autoScroll boolean
Used to enable auto scroll while drag and drop the element.
Default Value
- ‘false’
Example
//To set autoScroll API value during initialization
$("#draggable").ejDraggable({ autoScroll: true });
//Get or set the autoScroll API, after initialization:
//Gets the autoScroll value
$("#draggable").ejDraggable('option', 'autoScroll');
scrollSensitivity number
Represents when to start the scrolling inside the scroll container on dragging
Default Value
- ‘20’
Example
//To set scrollSensitivity API value during initialization
$("#draggable").ejDraggable({ scrollSensitivity: 22 });
//Get or set the scrollSensitivity API, after initialization:
//Gets the scrollSensitivity value
$("#draggable").ejDraggable('option', 'scrollSensitivity');
scrollSpeed number
Specifies how much distance of scroll should move on dragging once reached scroll sensitivity area.
Default Value
- ‘20’
Example
//To set scrollSpeed API value during initialization
$("#draggable").ejDraggable({ scrollSpeed: 25 });
//Get or set the scrollSpeed API, after initialization:
//Gets the scrollSpeed value
$("#draggable").ejDraggable('option', 'scrollSpeed');
Methods
destroy()
destroy in the draggable.
Example
< div id="draggable" > </div >
<script>
// Create draggableObj
var draggableObj = $("#draggable").data("ejDraggable");
draggableObj.destroy();
</script>
Events
destroy
This event is triggered when dragging element is destroyed.
Name | Type | Description |
---|---|---|
cancel | boolean | if the event should be canceled; otherwise, false. |
model |
|
returns the autocomplete model |
type | string | returns the name of the event |
Example
//destroy event for Draggable
$("#draggable").ejDraggable({
destroy: function(args) {}
});
drag
This event is triggered when the mouse is moved during the dragging.
</tr>Name | Type | Description |
---|---|---|
cancel | boolean | if the event should be canceled; otherwise, false. |
model |
|
returns the draggable model |
type | string | returns the name of the event |
element | object | returns the current draggable element object |
event | object | returns the event model values |
target | object | returns the exact mouse down target element |
Example
//drag event for Draggable
$("#draggable").ejDraggable({
drag: function(args) {}
});
dragStart
Supply a callback function to handle the drag start event as an init option.
</tr>Name | Type | Description |
---|---|---|
cancel | boolean | if the event should be canceled; otherwise, false. |
model |
|
returns the draggable model |
type | string | returns the name of the event |
element | object | returns the current draggable element object |
event | object | returns the event model values |
target | object | returns the exact mouse down target element |
Example
//dragStart event for Draggable
$("#draggable").ejDraggable({
dragStart: function(args) {}
});
dragStop
This event is triggered when the mouse is moved during the dragging.
</tr>Name | Type | Description |
---|---|---|
cancel | boolean | if the event should be canceled; otherwise, false. |
model |
|
returns the draggable model |
type | string | returns the name of the event |
element | object | returns the current draggable element object |
event | object | returns the event model values |
target | object | returns the exact mouse down target element |
Example
//dragStop event for Draggable
$("#draggable").ejDraggable({
dragStop: function(args) {}
});
helper
This event is triggered when dragged.
</tbody> </table> #### Example//helper event for Draggable
$("#draggable").ejDraggable({
helper: function () {
return $('<pre>').html("draggable").appendTo(document.body);}
});
Name | Type | Description |
---|---|---|
element | object | returns the draggable element object |
sender | object | returns the event model values |