Drag
The drag component allows to create a draggable zone you can control with your mouse.
scss
@import 'compotes/css/drag';js
import { Drag } from 'compotes'
const drag = new Drag('.c-drag')You need to have elements overflowing inside the component because it uses the css property overflow: auto;.
html
<div class="c-drag">
<!-- Your overflowing content -->
</div>Options
You can change some options from the component.
js
import { Drag } from 'compotes'
const drag = new Drag('.c-drag', {
init: true,
initEvents: true
})init(boolean): Init the component on creationinitEvents(boolean): Init events on the component
Methods
The drag component provides several methods to init and destroy it.
js
import { Drag } from 'compotes'
const drag = new Drag('.c-drag', {
init: false
})
drag.init()init(): Init the componentinitEvents(): Init component eventsdestroyEvents(): Destroy the component eventsdestroy(): Destroy the component
Data
You can access data from the component like this:
js
import { Drag } from 'compotes'
const drag = new Drag('.c-drag')
console.log(drag.isDraggable)options(options object): Get options used to init the componentisDraggable(boolean): Tell if the component is draggable or notisDragging(boolean): Tell if the component is currently dragging or not
Events
You can listen to emitted events directly on the drag element like this:
js
dragEl.addEventListener('c.drag.init', (e) => {
console.log(e.detail)// drag object
})c.drag.init: On component initc.drag.start: On component drag startc.drag.end: On component drag endc.drag.destroy: On component destroy