简体   繁体   English

JQuery UI - 将Draggable附加到Droppable

[英]JQuery UI - Append Draggable to Droppable

How do you append an item being dragged to a target element on drop, using jQueryUI's draggables/dropables? 如何使用jQueryUI的draggables / dropables将项目拖放到drop上的目标元素? It looks like the way jQuery UI works right now is it just moves the items around on the screen via absolute positioning. 它看起来像jQuery UI现在的工作方式是它只是通过绝对定位移动屏幕上的项目。 Unfortunately, this functionality makes form submissions useless, as you cannot get the positions of the values on submission. 遗憾的是,此功能使表单提交无效,因为您无法在提交时获取值的位置。

Thanks in advance for any items/pointers! 在此先感谢任何项目/指针!

If I understood correctly, you want the dragged element to be detached from it's current parent and be appended to the new one, right? 如果我理解正确,你希望拖动的元素与它的当前父元素分离并附加到新元素,对吧? You can use a helper to do the dragging (so the original element is not affected) and, upon drop, detach it and append it to the target (thanks @Oleg and @Brian for improving over my original answer). 您可以使用帮助程序进行拖动(因此原始元素不受影响),并在删除时将其分离并将其附加到目标(感谢@Oleg和@Brian以改进我原来的答案)。

$(myDraggable).draggable({
    helper:"clone",
    containment:"document"
});

$(myDroppable).droppable({
    drop:function(event, ui) {
        ui.draggable.detach().appendTo($(this));
    }
});

​ Working example at jsFiddle jsFiddle的工作示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM