2013-01-23 145 views
1

我想用jquery ui来模拟拖放,当拖放时不会从原始列表中删除项目,怎么可能?在这种情况下,我想保留在图库中的项目,但克隆到垃圾桶。Jquery droppable不删除元素

Jsbin例如http://jsbin.com/igevut/1/edit

$trash.droppable({ 
     accept: "#gallery > li", 
     activeClass: "ui-state-highlight", 
     drop: function(event, ui) { 
     deleteImage(ui.draggable); 
     } 
    }); 

function deleteImage($item) { 
     $item.fadeOut(function() { 
     var $list = $("ul", $trash).length ? 
      $("ul", $trash) : 
      $("<ul class='gallery ui-helper-reset'/>").appendTo($trash); 

     $item.find("a.ui-icon-trash").remove(); 
     $item.append(recycle_icon).appendTo($list).fadeIn(function() { 
      $item 
      .animate({ width: "48px" }) 
      .find("img") 
       .animate({ height: "36px" }); 
     }); 
     }); 
    } 

回答

2

只需在deleteImage功能开始添加$item = $item.clone()

0

您可以使用一种方法来返回一个助手,该助手将充当可拖动对象的克隆对象。

$("li", $gallery).draggable({ 
     cancel: "a.ui-icon", // clicking an icon won't initiate dragging 
     revert: "invalid", // when not dropped, the item will revert back to its initial position 
     containment: "document", 
     helper: getHelper, 
     cursor: "move" 
    }); 

function getHelper(event){ 

    // return html for the helper 
} 

参见链路http://shyalika.com/create_drag_and_drop_example为例