【发布时间】:2013-04-30 22:14:55
【问题描述】:
这是一个小提琴:http://jsfiddle.net/adMXj/
我有大型可拖动项目需要放入较小的容器中。当容器和项目大小相似时,这很好,但当它是一个大的可拖动元素时就不好了。
拖动后,我希望可拖动内容更改为“选定项目”。
你能帮忙吗?
这是我的 JS:
$('.items > li').draggable({
revert: "invalid",
helper: function(event) {
var helperList = $('<ul class="draggable-helper">');
if ($(this).is('.active')){
helperList.append($(this).siblings('.active').andSelf().clone());
} else {
helperList.append($(this).clone());
}
return helperList;
}
});
$('.drop-containers li').droppable({
drop: function(event, ui) {
console.log('dropped');
var $this = $(this);
var selectedObjects = new Array();
if (ui.draggable.hasClass('active')) {
console.log('active');
// get all active items
$('ul.items > li.active').each(function() {
console.log($(this).attr('id'));
selectedObjects.push($(this).attr('id'));
$(this).remove();
});
} else {
console.log('not active');
selectedObjects.push(ui.draggable.attr('id'));
ui.draggable.remove();
}
$this.append(', ' + selectedObjects.join(', '));
}
});
【问题讨论】:
标签: javascript jquery html css jquery-ui