I have a jquery dialog that is filled with draggable objects. The droppable target is outside of the dialog.
When I initiate a drag, the droppable responds correctly (visual indications that it is a droppable target) and after a drop the correct events trigger so I can correctly handle the drop.
The problem is that the dragged object stays visible only within the dialog, and does not "jump out".
I already have draggables that drag from one scrollable div to another without problem, but from a dialog to the page containing the dialog it does not work. The dialog contents scroll in whatever direction the drag is going.
My draggable arguments are as follows:
var draggableArguments={
revert: 'invalid',
helper:'clone',
containment: 'DOM',
zIndex: 999,
addClasses: false
}
theObject.draggable(draggableArguments);
Any suggestions so that my draggable objects can cross the dialog boundaries?
Thanks.
Using jQuery UI, we can make the DOM(Document Object Model) elements to drag anywhere within the view port. This can be done by clicking on the draggable object by mouse and dragging it anywhere within the view port. If the value of this option is set to false, it will prevent the DOM elements to be dragged .
Syntax: $(selector, context). draggable ("action", [params]);
We can disable drag and drop on HTML elements by setting the draggable attribute to false . We set draggable to false so we can't drag it. We add event listeners for the dragstart and drop events with addEventListener .
Limit draggable area using 'containment' option It is simple. All you have to do is, add an option called containment to the draggable() method. The containment option has a value parent.
Fixed, it was quite simple actually.
I just needed to use the appendTo option on the draggable so that the helper is appended to element where I want it to drag around (e.g. #page, a div that encompasses my page). This removes it from the dialog (which has an "overflow: auto" property, which adds scrollbars to extend the canvas so that the drag element is always within) and appends it to the #page element.
The only problem was my dialog had a pretty high zIndex, so I just incremented the zIndex option to be higher.
var draggableArguments={
revert: 'invalid',
helper:'clone',
appendTo: '#page',
containment: 'DOM',
zIndex: 1500,
addClasses: false
}
theObject.draggable(draggableArguments);
You have to do this:
$('.my_draggable').draggable({ helper:'clone', appendTo: 'body', scroll: false });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With