JSFiddle - React, Tailwind, and code Playground
HTML
<div id="dragIcons">
<img class="icons" id="icon1" width="90px" height="90px" src="http://icons.iconarchive.com/icons/artdesigner/tweet-my-web/128/single-bird-icon.png">
<img class="icons" id="icon2" width="90px" height="90px" src="http://icons.iconarchive.com/icons/artdesigner/tweet-my-web/128/single-bird-icon.png">
<img class="icons" id="icon3" width="90px" height="90px" src="http://icons.iconarchive.com/icons/artdesigner/tweet-my-web/128/single-bird-icon.png">
<img class="icons" id="icon4" width="90px" height="90px" src="http://icons.iconarchive.com/icons/artdesigner/tweet-my-web/128/single-bird-icon.png">
</div>
<div id="briefcase">
<div id="briefcase-full">
</div>
<div id="briefcase-droppable">
</div>
<button id="submit" type="button" onclick="onSubmit()">Submit</button>
<div id="listicon">
</div>
</div>
CSS
.draggable {
filter: alpha(opacity=100);
opacity: 1.0;
z-index: 100;
transition: none !important;
animation: pulse 0.3s alternate infinite;
}
.end-draggable {
animation: 0;
}
.dropped {
position: static !important;
transition: none !important;
animation: 0;
}
.icons {
margin-left: 10px;
}
#dragIcons {
padding: 5px;
min-height: 100px;
width: 500px;
margin-left: auto;
margin-right: auto;
}
#briefcase {
height: 531px;
width: 700px;
background: url("http://simpleicon.com/wp-content/uploads/Briefcase-12.png");
background-position: background-repeat: no-repeat;
position: absolute;
}
#briefcase-full {
height: 420px;
width: 580px;
}
#briefcase-droppable {
height: 90px;
width: 590px;
}
JavaScript
/* Drag and Drop */
$(function() {
var countDropped = 0;
$("#dragIcons img").draggable({
revert: "invalid",
refreshPositions: true,
cursor: "move",
cursorAt: {
top: 56,
left: 56
},
drag: function(event, ui) {
ui.helper.removeClass("end-draggable");
ui.helper.addClass("draggable");
},
stop: function(event, ui) {
ui.helper.addClass("end-draggable");
ui.helper.removeClass("draggable");
}
});
$('#reset').click(function(e) {
e.preventDefault();
var dropped_icon = $('#briefcase-droppable')
.children()
.detach()
.removeClass('dropped end-draggable')
.removeAttr('style')
.css('position', 'relative');
$('#dragIcons').append(dropped_icon);
$('#briefcase').css('background', 'url("http://simpleicon.com/wp-content/uploads/Briefcase-12.png")');
});
$("#briefcase-full").droppable({
greedy: true,
tolerance: 'touch',
drop: function(event, ui) {
var id = ui.draggable.attr("id");
if ($("#briefcase").length == 0) {
$("#briefcase-droppable").html("");
}
countDropped++;
ui.draggable.addClass("dropped");
$("#briefcase-droppable").append(ui.draggable);
}
});
$("#submit").click(function() {
var iconsid = " "
$("#briefcase-droppable").children(".icons").each(function() {
iconsid += $(this).attr("id");
});
$("#listicon").html(iconsid);
});
});