1.6.6 • Published 8 years ago

draggy v1.6.6

Weekly downloads
114
License
MIT
Repository
github
Last release
8 years ago
Draggy

<a href="/license"><img src="https://img.shields.io/npm/l/draggy.svg"/></a>
<img src="https://david-dm.org/dfcreative/draggy.svg"/>

Draggable behaviour for elements. Demo.

npm install draggy

var Draggable = require('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]An area within draggable element which is surely resides within movement limits. Useful if you need draggable element to be restricted not by it’s own shape, but by some inner shape.
precision1Round position to that extent, in pixels.
css3trueUse position or translate3d to place element. The first is more precise and reliable, the second is faster.
releasefalseContinue movement when user releases drag.
repeatfalseCycle movement by one of axis: 'x', 'y' or 'both'.
snipertrueSlow down movement by pressing Ctrl/Cmd.
threshold0A movement threshold required to start drag - whether array, number or function.
withindocumentRestrict movement within the container. Pass 'parent' to take parent node.
handleself.elementUse the passed element or selector as a handle for drag. Clicking not on the handle will be ignored. Passing null will ignore handle.
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,dragoveranddragout` 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.

API

NameDescription
Draggy.cacheWeakMap containing draggy instances for elements. Draggy.cache.get(element) - return draggy instance for the element.
Draggy.prototype.move(x, y)Move to a new position, taking into account axis and limits. You can redefine this method to implement custom kinds of movement restrictions, like circular movement. But who dares?
Draggy.prototype.stateCurrent drag state: 'idle', 'threshold', 'drag', 'release'.
Draggy.prototype.update(event?)Update movement limits. event is optional.

What draggy is not

  • It doesn’t do ghost move, as it is not draggable behaviour and can be implemented externally.
  • It doesn’t do mouse hiding on drag, as it is implementable externally via callbacks.
  • It doesn’t init itself automatically on elements as it is due to user to decide when to create/init draggable elements.
  • It doesn’t polyfill native draggable, as it targets to complete simple task of visual placement of element.
1.6.6

8 years ago

1.6.5

8 years ago

1.6.4

8 years ago

1.6.3

8 years ago

1.6.2

8 years ago

1.6.1

8 years ago

1.6.0

8 years ago

1.5.2

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.4.0

9 years ago

1.3.5

9 years ago

1.3.4

9 years ago

1.3.3

9 years ago

1.3.2

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.12

9 years ago

1.1.11

9 years ago

1.1.10

9 years ago

1.1.9

9 years ago

1.1.8

9 years ago

1.1.7

9 years ago

1.1.6

9 years ago

1.1.5

9 years ago

1.1.4

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.14

9 years ago

1.0.13

9 years ago

1.0.11

9 years ago

1.0.10

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.5

9 years ago

1.0.3

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.2.5

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.1.12

9 years ago

0.1.11

9 years ago

0.1.10

9 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago