2014-05-06 56 views

回答

0

我用解決方案的組合,在這個到達,#large_tiles和#small_tiles是兩個列表:

$(function() { 
$("#large_tiles li, #small_tiles li").draggable({ 
    zIndex: 2, 
    appendTo: "body", 
}); 

initDroppable($("#large_tiles li, #small_tiles li")); 

initSwap(); 
function initSwap() { 
    initDroppable($("#large_tiles li, #small_tiles li")); 
    initDraggable($("#large_tiles li, #small_tiles li")); 
} 
function initDraggable($elements) { 
    $elements.draggable({ 
     zIndex: 2, 
     appendTo: "body", 
     helper: "clone", 
     start: function(e, ui) { 
      $(ui.helper).addClass("clone"); 
     }, 
     cursorAt: { left:50, top:75 } 
    }); 
} 
function initDroppable($elements) { 
    $elements.droppable({ 
     activeClass: "active-tile", 
     hoverClass: "hover-tile", 
     over: function(event, ui) { 
      var $this = $(this); 
     }, 
     drop: function(event, ui) { 
      var $this = $(this); 
      var linew1 = $(this).after(ui.draggable.clone()); 
      var linew2 = $(ui.draggable).after($(this).clone()); 
      $(ui.draggable).remove(); 
      $(this).remove(); 
      initSwap(); 
     } 
    }); 
} 
}); 
相關問題