desandro / draggabilly

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

Nested draggables #150

Closed franciscolourenco closed 6 years ago

franciscolourenco commented 7 years ago

When draggables are nested, dragging the child will also drag the parent. Any solution to prevent parents from being dragged as well?

https://codepen.io/aristidesfl/pen/NdQzXP

desandro commented 7 years ago

Parallax!

Thanks for reporting this issue. I think the best way to resolve this issue is use handles, using the back handle technique

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

franciscolourenco commented 7 years ago

What do you think about adding an option to exclude the children from triggering the drag? Something in the lines of https://github.com/aristidesfl/draggabilly/commit/4c52fb1c73c0795bbfb5ebd1ba4450ad1b77bb7c

desandro commented 7 years ago

Nice move! I don't feel this option is necessary to be added to master. However, you can monkey punch it with this code

Draggabilly.defaults.excludeChildren = false;

var pointerDown = Draggabilly.prototype.pointerDown;
Draggabilly.prototype.pointerDown = function( event, pointer ) {
  if (this.options.excludeChildren && this.element !== event.target) {
      return;
  }

  pointerDown.apply( this, arguments );
};