Drag Action
Usage notes
Drag actions are decorators which add draggable functionality to elements.
Default
You can drag me
Toggle markup
<span coral-dragaction="">
<p>You can drag me</p>
<img alt="" src="http://via.placeholder.com/200x100">
</span>
Limited to a single axis
You can drag me on the horizontal axis only
Toggle markup
<span coral-dragaction="" coral-dragaction-axis="horizontal">You can drag me on the horizontal axis only</span>
Limited to a handle
I can be dragged only by this
handle or this handle
Toggle markup
<div coral-dragaction="" coral-dragaction-handle=".handle1, .handle2">
I can be dragged only by this
<span class="handle1"><b>handle</b></span> or this <span class="handle2"><i>handle</i></span>
</div>
Containment
You can not drag me out
Toggle markup
<div style="height:200px;width:200px;background: #eee;overflow:scroll;">
<div coral-dragaction="" coral-dragaction-containment="" style="width:50px;border:1px solid #999;">
You can not drag me out
</div>
</div>
Automatic window scroll
You can drag me and window will scroll
Toggle markup
<span coral-dragaction="" coral-dragaction-scroll="">You can drag me and window will scroll</span>
Automatic container scroll
You can drag me and container will scroll
Toggle markup
<div style="overflow: auto;border: 1px solid; height:500px;width:500px;">
<span coral-dragaction="" coral-dragaction-scroll="">You can drag me and container will scroll</span>
<div style="background: linear-gradient(lightgoldenrodyellow, lightcoral); height:1000px;width:1000px;" tabindex="0"></div>
</div>
Drag'n'drop
You can drop me on #dropzone
I'm #dropzone
Toggle markup
<span id="dragaction" coral-dragaction="" coral-dragaction-dropzone="#dropzone">You can drop me on #dropzone</span>
<div id="dropzone" style="height:200px;width:200px;background:#eee;">I'm #dropzone</div>
<script>
window.addEventListener('load', function() {
document.getElementById('dragaction').addEventListener('coral-dragaction:drop', function(event) {
event.detail.dropElement.style.background = 'beige';
});
});
</script>
Initialized with JS
You can drag me vertically
Toggle markup
<span id="init-js">You can drag me vertically</span>
<script>
window.addEventListener('load', function() {
var dragAction = new Coral.DragAction('#init-js');
dragAction.axis = 'vertical';
});
</script>