I’ve been trying to implement some simple draggable / droppable code (link below) with no success. The items drag, revert and stay in containment. However, when dropped in the droppable area the item gives the alert, as it should, but it is then no longer draggable.
Ideally, I would like to have the item draggable between the drag and drop areas. Just in case the user moves it to the droppable area and then changes their mind. Once in the droppable area, I would like to also allow the item to be movable in there.
Am I overlooking something obvious? Everything I found searching looked like it was pretty basic and straightforward to implement.
I’ve been searching and trying a few things, but haven’t had any luck.
<div class="build_board_text" id="build_board_text">
<div id="src_landscape_8-5x11">
<div id="draggable_1" class="draggable_item">
<br />Text 1.
</div>
<div id="draggable_2" class="draggable_item">
<br />Text 2.
</div>
</div><!-- source list -->
<div id="dst_landscape_8-5x11"> </div><!-- destination list -->
</div
$(function() {
$('div', $('#src_landscape_8-5x11')).draggable({
revert: 'invalid',
containment: '#build_board_text'
});
$('#dst_landscape_8-5x11').droppable({
accept: '#src_landscape_8-5x11 > div',
drop: function() {
alert('Dropped!');
}
});
$('#src_landscape_8-5x11').droppable({
accept: '#dst_landscape_8-5x11 div',
drop: function() {
alert('Dropped back!');
}
});
});
Not entirely sure why, but if you remove
position:relativefrom#dst_landscape_8-5x11then it works.EDIT: Also, change your source on the 2nd one to match the first:
The items originate in
src_...so they are always considered to be part of that it seems.