Disable drop if div has already been dropped?

独自空忆成欢 提交于 2019-12-07 08:24:24

The docs(Look under "methods" tab) indicate that to disable you use:

$(this).droppable( 'disable' );

And to enable you use

$(this).droppable( 'enable' );

Update: Check this live example: http://jsfiddle.net/QqJRs/ Drag one of the red squares to the big box and drop it (it turns green to indicate its dropped). You cant drop any of the others to this box while one is inside. Now drag that one out (It turns back red to indicate its removed). Now you can drop any of the others in its place.

The crux of this is as I described in my comment below; when you drop an item in a container associate the container with the item:

drop: function(event,ui){
    ui.draggable.addClass( 'dropped' ); // taken from your code & I used to change color

   ui.draggable.data('droppedin',$(this)); // associate the container
    $(this).droppable('disable'); // disable the droppable
}

Then when you drag it again, unassociate and re-enable:

drag: function(event,ui){
       if($(this).data('droppedin')){
           $(this).data('droppedin').droppable('enable'); v// re-enable
           $(this).data('droppedin',null);  // de-associate
           $(this).removeClass( 'dropped' ) // remove class
       }
   }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!