When I make a draggable clone and drop it in a droppable I cannot drag it again

后端 未结 4 553
执念已碎
执念已碎 2020-11-28 20:52

When I make a draggable clone and drop it in a droppable I cannot drag it again. How do I do that? Secondly I can only figure out how to us .append to add the c

4条回答
  •  忘掉有多难
    2020-11-28 21:10

    Here is my solution, it allows for dragging and dropping a clone, and then replacing it after as needed by another drag and drop. It also has a callback function parameter which passes back the dropped div object so that you can do something with the jquery selected div once dropped.

    refreshDragDrop = function(dragClassName,dropDivId, callback) {
      $( "." + dragClassName ).draggable({
        connectToSortable: "#" + dropDivId,
        helper: "clone",
        revert: "invalid"
      });
      $("#" + dropDivId).droppable({
        accept: '.' + dragClassName,
        drop: function (event, ui) {
          var $this = $(this),
            maxItemsCount = 1;
          if ($this.children('div').length == maxItemsCount ){
            //too many item,just replace
            $(this).html($(ui.draggable).clone());
            //ui.sender.draggable('cancel');
          } else {
            $(this).append($(ui.draggable).clone());
          }
          if (typeof callback == "function") callback($this.children('div'));
        }
      });
    }
    

提交回复
热议问题