$(function() {
function makeDrag(o) {
o.draggable({
grid: [40, 40],
containment: "#builder"
});
}
$("#catalog .widget").click(function(e) {
var w = $(this).clone().removeAttr("id");
w.appendTo("#builder").position({
my: "left top",
at: "left top",
of: $(this)
});
w.animate({
top: 0,
left: 0
}, "fast");
makeDrag(w);
});
$("#trashWidget").droppable({
greedy: 'true',
accept: function() {
return true;
},
drop: function(event, ui) {
tolerance: 'fit',
$(ui.draggable).remove();
}
});
});
#products {
width: 200px;
float: left;
}
#catalog {
padding: 20px 0px 0px 0px;
border: 1px dotted rgb(204, 204, 204);
}
.widget {
border: 1px dotted rgb(204, 204, 204);
width: 50px;
height: 50px;
background-color: #eae9e4;
}
#builder {
padding: 0px 0px 0px 0px;
float: left;
border: 1px dotted rgb(204, 204, 204);
width: 500px;
height: 400px;
position: relative;
}
#builder .widget {
position: absolute;
background-color: #eae9ff;
border: 1px dotted rgb(175, 175, 175);
}
#trashWidget {
width: 46px;
height: 46px;
float: right;
padding: 0px 0px 0px 0px;
border: 1px dotted rgb(204, 204, 204);
}
a {
color: 0076A3;
text-decoration: none;
outline: none;
font: normal 11px/13px Verdana, Helvetica, sans-serif;
}
a:active {
color: #0076A3;
text-decoration: underline;
}
a:visited {
color: #0076A3;
text-decoration: none;
}
a:hover {
color: #0076A3;
text-decoration: underline;
}
span {
font: normal 11px/13px Verdana, Helvetica, sans-serif;
}
div {
font: normal 11px/13px Verdana, Helvetica, sans-serif;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div>
<div style="width:750px; display: block;">
<div id="products">
<span style="color:#D8781A;">WIDGET SELECTOR</span>
<div id="catalog" align="left">
<div>
<ul style="list-style:none;">
<div id="widget1" class="widget" style="width:50px; height: 50px;"></div>WIDGET 1
<div id="widget2" class="widget" style="width:100px; height:100px;"></div>WIDGET 2
<div id="widget3" class="widget" style="width:75px; height:75px;"></div>WIDGET 3
</ul>
</div>
</div>
</div>
<div style="padding:0px 0px 0px 0px; float:left;">
<br />
</div>
<span style="color:#D8781A;">WIDGET BUILDER</span>
<br />
<div id="builder">
<div>
<div id="trashWidget">trash</div>
</div>
</div>
</div>
</div>