JQuery-UI 拖放和重新拖动克隆上的重新拖动
我使用以下代码来扩展下载中包含的 JQuery-UI 演示。我正在尝试设置一个容器,用户可以将项目拖入其中,然后在容器内移动项目。我合并了当我制作一个可拖动克隆并将其放入可放置文件中时的答案,我无法再次拖动它这适用于一个问题。
<script>
$(document).ready(function() {
$("#droppable").droppable({
accept: '.ui-widget-content',
drop: function(event, ui) {
if($(ui).parent(":not(:has(#id1))")){
$(this).append($(ui.helper).clone().attr("id", "id1"));
}
$("#id1").draggable({
containment: 'parent',
});
}
});
$(".ui-widget-content").draggable({helper: 'clone'});
});
</script>
div class="demo">
<div id="draggable" class="ui-widget-content">
<p>Drag me around</p>
</div>
<div id="droppable" class="ui-widget-header">
<p>Drop here</p>
</div>
当一个项目被放置到可放置容器上时,它可以被拖动一次,并且当该项目在拖动之后被放置时,它就失去了拖动功能。
在将项目添加到可放置容器后,如何允许多次拖动该项目?
I am using the following code to extend the JQuery-UI demos included with the download. I am trying to set up a container that the user can drag items into and then move the items around within the container. I incorporated the answer from When I make a draggable clone and drop it in a droppable I cannot drag it again which works with one problem.
<script>
$(document).ready(function() {
$("#droppable").droppable({
accept: '.ui-widget-content',
drop: function(event, ui) {
if($(ui).parent(":not(:has(#id1))")){
$(this).append($(ui.helper).clone().attr("id", "id1"));
}
$("#id1").draggable({
containment: 'parent',
});
}
});
$(".ui-widget-content").draggable({helper: 'clone'});
});
</script>
div class="demo">
<div id="draggable" class="ui-widget-content">
<p>Drag me around</p>
</div>
<div id="droppable" class="ui-widget-header">
<p>Drop here</p>
</div>
When an item is dropped onto the droppable container it can be dragged one time and when it is dropped after that drag it loses its dragging capability.
How do I allow for the item to be dragged multiple times after it has been added to the droppable container?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您将项目放入容器中时,您应该检查可放置元素的“id”是否已添加到容器中。
看一下以下示例:
http://highoncoding.com/Articles/381_Drag_And_Drop_With_Persistence_Using_JQuery.aspx
When you drop the item into the container you should check if the "id" of the droppable element is already added to the container.
Take a look at the following example:
http://highoncoding.com/Articles/381_Drag_And_Drop_With_Persistence_Using_JQuery.aspx
这可能会有所帮助。将
#draggable
项目拖动到#droppable
容器后,#droppable
中的项目必须再次变为可拖动。这是代码:This might help. After you drag your
#draggable
item to the#droppable
container, the item in the#droppable
must be made draggable again. Here is the code for this: