我有一个div,应用了jQuery UI Draggable。我想要做的是点击并拖动它,创建一个克隆体,保留在dom中,在放置时不被删除。
想象一下一副牌,我的盒子元素就是整副牌,我想从牌堆上取出卡牌/ div,并让它们散布在我的页面上,但它们会是原始div的克隆版本。 我只想确保您不能创建另一个克隆的div的克隆体。
我已经使用了以下内容,但并未按照我所希望的方式工作:
$(".box").draggable({
axis: 'y',
containment: 'html',
start: function(event, ui) {
$(this).clone().appendTo('body');
}
});
我找到了解决方案:
$(".box-clone").live('mouseover', function() {
$(this).draggable({
axis: 'y',
containment: 'html'
});
});
$(".box").draggable({
axis: 'y',
containment: 'html',
helper: 'clone'
stop: function(event, ui) {
$(ui.helper).clone(true).removeClass('box ui-draggable ui-draggable-dragging').addClass('box-clone').appendTo('body');
}
});