desandro / draggabilly

:point_down: Make that shiz draggable
https://draggabilly.desandro.com
MIT License
3.86k stars 387 forks source link

how to get the current drag object in the drageMove listener? #164

Closed linsywu closed 6 years ago

linsywu commented 7 years ago

I want off this drag move event when the moveVector more than 100,but i cant'get the current draggie in the dragMove callback ,how can I get it?

desandro commented 7 years ago

In vanilla JS, within an event listener function you can use this to get the instance of the Draggabilly.

var draggableElems = document.querySelectorAll('.draggable');

for ( var i=0; i < draggableElems.length; i++ ) {
  var draggableElem = draggableElems[i];
  var draggie = new Draggabilly( draggableElem );
  draggie.on( 'dragStart', onDragStart );
}

function onDragStart() {
  console.log( this.element.textContent );
}

See demo https://codepen.io/desandro/pen/fe40920fa16fa44b17b7caa0b87ea5f2