我试图拖动拖放的元素,它是被拖动元素的克隆,但当我拖动该元素时,它会在页面中创建另一个元素。这是我的代码..
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());
}
});
});有没有什么遗漏的命令可以让每个拖拽都变成一个新的克隆?
发布于 2012-01-09 22:24:58
您应该有一个类,以便指示元素已被删除,并且您可以移动它,但不应该克隆它。你可以看看这把小提琴:http://jsfiddle.net/scaillerie/njYqA/。在drop的处理程序中,我刚刚替换为以下代码:
if (!ui.draggable.hasClass("dropped"))
jQuery(this).append(jQuery(ui.draggable).clone().addClass("dropped").draggable());发布于 2012-01-09 18:19:20
jQuery(this).append(jQuery(ui.draggable).clone().draggable());你忘了.clone()了吗
https://stackoverflow.com/questions/8786807
复制相似问题