2.0.5 • Published 8 months ago

draggy v2.0.5

Weekly downloads
114
License
MIT
Repository
github
Last release
8 months ago

Draggy

Make any element draggable. Demo.

npm install draggy

import Draggable from 'draggy';

//make an element draggable
var el = document.querySelector('.my-element');
var draggy = new Draggable(el, {
	release: true,
	sniper: false,
	axis: 'x'
});

//bind event handler
draggy.on('drag', function () {
	// ...
});

Options

ParameterDefaultDescription
axisnullRestrict movement by axis: 'x', 'y' or null.
pin[0,0, selfWidth, selfHeight]Defines a smaller area within the draggable element that stays within movement limits. Useful to restrict movement based on an inner shape rather than the full element.
precision1Round position to that extent, in pixels.
css3trueUse position vs translate3d to place element. The first is more precise and reliable, the second is faster.
releasefalseContinue movement when user releases drag.
repeatfalseLoop movement by one of axis: 'x', 'y' or 'both'.
snipertrueSlow down movement by pressing Ctrl/Cmd.
threshold0A movement threshold required to start drag - whether an array, number or function.
withindocumentRestrict movement within the container. Pass 'parent' to use parent node.
handleself.elementUse element or selector as a handle for drag. Clicking outside the handle is ignored.
cancelundefinedIgnore dragging started on the elements matching the selector.
droppableundefinedSelector, element or list of elements to detect droppable areas. For each drop element will be invoked drop, dragover and dragout events.

Events

NameDescription
dragstartDrag started. Called both on element/controller.
thresholdEntered threshold mode. Called on controller.
dragDrag iteration. Called both on element/controller.
trackTrack movement. Called on controller.
releaseUser released drag. Called on controller.
dragendDrag has completely finished. Called both on element/controller.
dragoverCalled on self and on drop target.
dragoutCalled on self and on drop target.
dropCalled on self and on drop target.

What draggy is not

  • It doesn’t do ghost move, as it is not draggable behavior and can be implemented externally.
  • It doesn’t do mouse hiding on drag, as it can be done via callbacks.
  • It doesn’t init itself automatically - it's up to you to decide when to create/init draggable.
  • It doesn’t polyfill native draggable, as it targets to complete simple task of visual placement of element.

Alternatives

License

MIT

2.0.3

8 months ago

2.0.2

8 months ago

2.0.5

8 months ago

2.0.4

8 months ago

2.0.1

8 months ago

2.0.0

8 months ago

1.6.6

9 years ago

1.6.5

9 years ago

1.6.4

9 years ago

1.6.3

9 years ago

1.6.2

9 years ago

1.6.1

9 years ago

1.6.0

9 years ago

1.5.2

9 years ago

1.5.1

9 years ago

1.5.0

9 years ago

1.4.0

10 years ago

1.3.5

10 years ago

1.3.4

10 years ago

1.3.3

10 years ago

1.3.2

10 years ago

1.3.1

10 years ago

1.3.0

10 years ago

1.2.3

10 years ago

1.2.2

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.12

10 years ago

1.1.11

10 years ago

1.1.10

10 years ago

1.1.9

10 years ago

1.1.8

10 years ago

1.1.7

10 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.14

10 years ago

1.0.13

10 years ago

1.0.11

10 years ago

1.0.10

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.5

10 years ago

1.0.3

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.2.5

11 years ago

0.2.3

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.1.12

11 years ago

0.1.11

11 years ago

0.1.10

11 years ago

0.1.5

11 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago

0.0.0

11 years ago