2012-01-09 103 views
1

我试图拖动拖动的元素,这是拖动元素的克隆,但是当我拖动元素时,它会在页面中创建另一个元素。这是我的代码..拖动元素在jQuery中的克隆

jQuery(function() { 
    jQuery(".component").draggable({ 
     // use a helper-clone that is append to 'body' so is not 'contained' by a pane 
     helper: function() { 
      return jQuery(this).clone().appendTo('body').css({'zIndex':5}); 
     }, 
     cursor: 'move' 
    }); 

    jQuery('.ui-layout-center').droppable({ 
     activeClass: 'ui-state-hover', 
     accept: '.component', 
     drop: function(event, ui) { 
      jQuery(this).append(jQuery(ui.draggable).clone().draggable()); 
     } 
    }); 
}); 

是否有任何缺少的命令,使每一个拖动一个新的克隆?

回答

0

jQuery(this).append(jQuery(ui.draggable).clone().draggable());你忘了.clone()

+0

好的谢谢。但我做到了,我想要 – Jackson 2012-01-09 11:32:23

1

你应该已经为了表明元素的类已被删除,您可以移动,但你不应该克隆。 你可以看看这个小提琴:http://jsfiddle.net/scaillerie/njYqA/。 在处理器中,我只是用这段代码替换:

if (!ui.draggable.hasClass("dropped")) 
    jQuery(this).append(jQuery(ui.draggable).clone().addClass("dropped").draggable());