[英]how to make Jquery draggable element append to droppable when dropped
Edit: I want the final cloned element to be draggable to any position in the droppable, i do not want it to be sortable.编辑:我希望最终克隆的元素可以拖动到 droppable 中的任何位置,我不希望它可以排序。
I'm trying to append my draggable-clone element to droppable element when it is dropped.我正在尝试将我的draggable-clone元素附加到droppable元素。 when the draggable element is inside the droppable element, i want it(the draggable element) to be draggable inside the droppable .
当可拖动元素在droppable元素内时,我希望它(可拖动元素)在droppable内可拖动。 Right now the draggable-clone element can be dragged from its position and when it is dropped it becomes undraggable.
现在可拖动克隆元素可以从其位置拖动,当它被放下时它变得不可拖动。 So please help me in achieving my goal.
所以请帮助我实现我的目标。 Thanks.
谢谢。
here is the code:这是代码:
$(function () { $('#draggable').draggable({ helper: 'clone' }); $('#droppable1, #droppable2').droppable({ drop: function (event, ui) { $(this) .append(ui.helper.clone(false).css({ position: 'relative', left: '0px', top: '0px' })); } }); });
.well { width: 150px; height: 150px; border: 3px solid red; } .ii{ float:left; margin-top: 20px; margin-right: 20px; border: 3px solid blue; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.9.1/jquery-ui.min.js"></script> <div class="well"> <div id="draggable">CONTENT</div> </div> <div id="droppable1" class="ii well col-md-3" style="z-index:-1;"></div> <div id="droppable2" class="ii well col-md-9" style="z-index:-1;"></div>
The initial element is created as a draggable one on the document ready event, but the new element created when you drop never has this code run on it.初始元素在文档就绪事件上创建为可拖动元素,但在您放下时创建的新元素从未在其上运行此代码。 It needs to be added to the "drop" event:
它需要添加到“drop”事件中:
$('#droppable1, #droppable2').droppable({
drop: function (event, ui) {
$(this)
.append(ui.helper.clone(false).css({
position: 'relative',
left: '0px',
top: '0px'
}));
/* New stuff here: */
$('.ui-draggable').draggable({
helper: 'clone'
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.