Using jQuery and Jquery UI, I have a draggable and droppable area, the draggable item has the following helper
$(".draggable").draggable({
revert: 'invalid',
grid: [ 20,20 ],
cursorAt: { top: -12, left: -20 },
helper: function(event) {
return $('<div class="helper"></div>');
}
});
How do I get the helper to be added
to the droppable area?
jQueryUI provides draggable() method to make any DOM element draggable. Once the element is draggable, you can move that element by clicking on it with the mouse and dragging it anywhere within the viewport.
Check whether your draggable object is already loaded in the viewport. If it is not, it won't work properly. JUST AFTER the draggable object to be absolutely sure that everything is loaded at the correct time. When you'll be sure everything is ok, then you'll be able to refactor.
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 .
After a bit more investigation and another question I have worked this out.
The in the drop
event on the droppable element you need to clone the helper as you cannot drop the actual helper that shows during dragging.
$("#droppable").droppable({
drop: function(event, ui) {
var newDiv = $(ui.helper).clone(false)
.removeClass('ui-draggable-dragging')
.css({position:'absolute', left:0, top:ui.offset.top - 12});
$(this).append(newDiv);
}
});
Thanks also to Jason Benson.
Alan
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