我试图让一个容器接受 2 个不同的可拖动元素。我希望容器要求添加和接受两个元素,然后触发事件
$(document).ready(function () {
var dfd1 = $.Deferred();
var dfd2 = $.Deferred();
$('#draggable').draggable({
start: function () {
$(this).parent().animate({
opacity: '0.5'
}, 1000);
},
stop: function () {
$(this).parent().animate({
opacity: '1'
}, 1000).end().remove();
}
});
$('#droppable').droppable({
accept: ("#draggable", "#draggable2"),
drop: function (event, ui) {
$(this).html('Dropped');
dfd1.resolve();
dfd2.resolve();
}
});
// this will trigger when both dfds have been resolved
$.when(dfd1.promise(), dfd2.promise()).then(function () {
alert("done!")
});
});