desandro / draggabilly

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

Question: Easiest way to disable other draggable items #95

Closed jamielob closed 9 years ago

jamielob commented 9 years ago

Hi!

What's the easiest way to disable all other draggable items once you have started dragging on something?

p.s. Fantastic piece of kit @desandro - best drag library I've used so far.

desandro commented 9 years ago

Thanks for the kind words :) Here's the jQuery code. See demo http://codepen.io/desandro/pen/LVQqgm

var $draggable = $('.draggable').draggabilly();

// disable other draggabillies on dragStart
$draggable.on( 'dragStart', function( event ) {
  $draggable.filter( function( i, elem ) {
    return elem != event.target;
  }).draggabilly('disable');
});
// re-enable on dragEnd
$draggable.on( 'dragEnd', function() {
  $draggable.draggabilly('enable');
});

Demo with vanilla JS: http://codepen.io/desandro/pen/GJQzPL

jamielob commented 9 years ago

Perfect. Thanks!