大家好,我想就 css - jquery 拖放问题寻求帮助。我熟悉将 div 定位到其容器的底部(位置:相对 -> 位置:绝对;底部:0;)。
目标:我想从存储 div 中拖动项目并放下另一个 div 并将这些项目从底部到顶部垂直放置。就像建造一座塔(2D)或其他东西。如何将这些项目浮动到新容器的底部和彼此的顶部?
谢谢 - 贾尼
#drop {
height:300px;
background:#EDCCE9;
}
#drag {
margin-top:10px;
height:50px;
background:#B8D8E3;
}
#drag img {
display: inline-block;
margin-right:10px;
}
.temp {
display: block;
}
$('.item').draggable({
containment: 'document',
revert: true,
helper: 'clone',
start: function () {
contents = $(this).html();
currentValue = $(this).attr('value');
}
});
$('#drop').droppable({
hoverClass: 'border',
accept: '.item',
drop: function (event, ui) {
$(this).append($(ui.draggable).clone());
$('#drop .item').addClass('temp');
$('.temp').removeClass('ui.draggable item');
$(".temp").draggable({
containment: 'document',
revert: true
});
}
});
$('#drag').droppable({
hoverClass: 'border',
accept: '.temp',
drop: function (event, ui) {
$(ui.draggable).remove();
}
});
<div id="drop"></div>
<div id="drag">
<img src="blocks/a.png" width="50px" height="50px" class="item" />
<img src="blocks/b.png" width="50px" height="50px" class="item" />
<img src="blocks/c.png" width="50px" height="50px" class="item" />
<img src="blocks/d.png" width="50px" height="50px" class="item" />
<img src="blocks/e.png" width="50px" height="50px" class="item" />
<img src="blocks/f.png" width="50px" height="50px" class="item" />
</div>