【发布时间】:2016-03-26 14:27:26
【问题描述】:
我是 Jquery UI Draggable 的新手。这是我的问题,我有 2 个 div,哪些项目可以在两个 div 之间转移。为什么当一个div转移到另一个div然后返回时,可拖动效果会丢失?我不能使用助手克隆。元素必须始终可拖动。
这里是在 jsfiddle https://jsfiddle.net/w7vjuuqx/7/ 上复制问题:
- 将蓝框从红框拖放到绿框。
- 将蓝框从绿框拖放到红框。
- 重复步骤1。这里拖拽效果丢失了。
JS:
$('.item').draggable();
$( '#placeholder' ).droppable({
accept: '.item',
drop: function( event, ui ) {
var droppable = $(this);
var draggable = ui.draggable;
$(draggable).attr('class', 'new_item_inside');
draggable.appendTo(droppable);
draggable.css({position: 'absolute', top: '0px', left: '0px'});
alert('hello');
}
});
$( '#item_holder' ).droppable({
accept: '.new_item_inside',
drop: function( event, ui ) {
var droppable = $(this);
var draggable = ui.draggable;
// var html = $(ui.draggable).clone(true);
ui.draggable.draggable('enable');
$(draggable).attr('class', 'item');
draggable.appendTo('#item_holder');
draggable.css({position: 'static', float: 'left'});
}
});
HTML:
<div id="item_holder" style="width:100px;height:100px;background-color:red">
<div class="item" style="width:20px;height:20px;background-color:blue">
test
</div>
</div>
<div id="placeholder" style="width:100px;height:100px;background-color:green;border-style: solid;display: inline-block;position:relative">
</div>
【问题讨论】:
标签: javascript jquery