简体   繁体   English

结合使用jQuery和可拖动/可拖放的还原

[英]Combining revert with jQuery draggable/droppable

I'm using the drag and drop plugin with jQuery UI. 我在jQuery UI中使用了拖放插件。 I'd like to make it so that the draggable container can only be dragged and dropped on the container. 我想这样做,以便只能将可拖动容器拖放到容器上。 In the demonstration: 在演示中:

http://jqueryui.com/demos/droppable/#revert http://jqueryui.com/demos/droppable/#revert

It has 2 options. 它有2个选项。 One is to revert when it drags to the container, the second is to revert when it isn't dragged to the container. 一种是在拖动到容器时还原,第二种是在未拖动到容器时还原。

Is there a way to combine these two? 有没有办法将两者结合起来? I don't want to be able to drag the #draggable container anywhere where there isn't a #droppable container. 我不想将#draggable容器拖到没有#droppable容器的任何地方。

As stated above, I found the solution by adding : 如上所述,我通过添加以下内容找到了解决方案:

$('#draggable2').remove(); 
$('#draggable').draggable({ revert: true });

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

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