JSFiddle - React, Tailwind, and code Playground
by ifaour
HTML
<div><button type="button">Add box</button></div>
<div style="float: left;"><h3>Drop here:</h3>
<div class="drop1 droppable"></div>
</div>
<div style="float: left;"><h3>Drop here:</h3>
<div class="drop2 droppable"></div>
</div>
<div style="float: left;"><h3>Out of scope!</h3>
<div id="droppable2"></div>
</div>
<div class="clear"></div>
<div id="cont">
<div class="drag">Drag me</div>
<div class="drag">Drag me</div>
</div>
CSS
.droppable, #droppable2 {width: 150px; height: 150px; background-color: yellow; float: left; margin: 0 10px; overflow: auto}
h3 {margin: 0 10px}
.clear {clear: both;}
.drag {width: 50px; height: 50px; background-color: red; float: left; margin: 5px}
JavaScript
$(function() {
var dragOptions = {
revert: "invalid",
scope: "items",
helper: "clone"
}
$('.drag').draggable(dragOptions);
$('.droppable').droppable({
scope: "items",
drop: function(e, ui) {
var $drop = $(this);
$(ui.draggable).draggable({
"disabled": true
}).appendTo($drop);
}
});
$('#droppable2').droppable();
$(':button').click(function() {
var $box = $('<div class="drag">Drag me</div>');
$('#cont').append($box);
$box.draggable(dragOptions);
});
});