All Drag
Javascript mobile-friendly small and simple plugin provided for you to meet all needs of drag such as slide and free drag
Installation
cdn
<link href="https://cdn.jsdelivr.net/npm/all_drag/all_drag_style.css" rel="stylesheet" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/all-drag@1.2.0/index_minify.js" rel="stylesheet" crossorigin="anonymous"></script>
download
source codeUsage
to start and set up an element to all drag plugin we need to:
Note: for use with panel to drag you should use an element with closing tag(except p tag) Note 2:if you use this package from cdn, there is no need to import
import{ALL_DRAG} from "all_drag";
ALL_DRAG.create(<'your element id'>,options);
General Options
Usage Example
ALL_DRAG.create(<'your element id'>,{
drag_cursor:'grabbing',
drag_type:{
type: 'slide'
},
draggableAllowedNumber: 2,
panel: {
hover_cursor: 'grab',
panel_height: '30',
panel_color: '#adb8ba',
},
revert: true,
transitionDuration: '.7',
});
Options
Name | Type | Options | Default | Description | |
---|---|---|---|---|---|
drag_type | Object | - | - | In this object we choose type of drag and other drag options that We will get acquainted with them in their own sections | |
type | String | free/slide | free | choose the type of drag such as slide or free drag | |
drag_cursor | String | - | false | write name style of the cursor on dragging event | |
revert | boolean | - | false | choose between your element will be return to it first place after stop drag event or not | |
transitionDuration | Number | - | '.2' | write the number of transition time (revert or close slide drag & ...) per second | |
draggableAllowedNumber | Number | - | 0(infinite) | Write how much drag your users are allowed to use | |
panel | Object | - | - | in this object, we choose between the below options for panel (in free panel optional to use) | |
hover_cursor | String | - | auto | write name style of the cursor on panel hover event | |
panel_color | String | - | #656565 | write your panel color | |
panel_height | Number | - | 15 | write your panel height (per px) | |
panel_radius | Number | - | 10 | panel redius (will be set by direction of panel) | |
panel_hide | Boolean | - | false | choose is panel will be transparent or not |
Free Drag
Usage
to start and set up an element to free drag we need to set type option to 'free' (in drag type
object)
Note: for use with panel to drag you should use an element with closing tag
ALL_DRAG.create(<'your element id'>,{
drag_type:{
type: 'free',
freeDrag: {
drag_place: 'self',
...('other object options')
}
}
});
Options
Name | Type | Options | Default | Description | |
---|---|---|---|---|---|
drag_place | String | self/panel | 'self' | choose place, where to drag on drag event (panel or element itSelf) | |
panel_side | String | top/left/bottom/right | 'top' | if you choose panel in previous option you can set direction of panel to place relation to element | |
drag_style | String | flat/elevate | 'flat' | choose style of element on dragging event between flat or elevate options | |
drag_scale | Number | - | '1.05' | if you choose elevate in previous option you can set scale size of element on drag event | |
drag_shadow_color | String | - | '#737373' | if you choose elevate in previous option you can set color of shadow on drag event | |
drag_shadow_blur | Number | - | '5' | if you choose elevate in previous option you can set blur size of shadow on drag event | |
drag_shadow_distance | Number | - | '5' | if you choose elevate in previous option you can set distance of Y direction shadow on drag event | |
allowedDistrict | String | - | false | in this section, if you want to drag the element inside another element you should insert the name of the second element ID in this option |
Events
Name | Description | |
---|---|---|
allFreeDragStart | Fired when mouse down | |
allFreeDragMove | Fired when mouse move on drag | |
allFreeDragStop | Fired when mouse up on drag |
Example
Drag me
ALL_DRAG.create('example_elem_free',{
drag_type:{
type: 'free',
freeDrag: {
drag_place: 'self',
panel_side: 'top',
drag_style: 'elevate',
allowedDistrict: 'free_drag_example_cont',
},
draggableAllowedNumber: 0,
panel: {
hover_cursor: 'grab',
panel_height: '30',
panel_color: '#adb8ba',
},
revert: false,
transitionDuration: '.3',
}
});
© 2021 Behnam Rahimpour. Plugin © All Drag