我想让不同的形状div可拖动并可放置到容器中。另外,我们放入容器的不同形状也可以在容器区域中拖曳而不会相互重叠。
$(".square").draggable({helper: 'clone'});
$(".rect").draggable({helper: 'clone'});
$("#canvas").droppable({
accept: ".rect, .square",
drop: function(ev,ui){
$(ui.draggable).clone().appendTo(this);
}
});

#canvas {
height: 100px;
border: 1px solid lightgrey;
}
.square, .rect {
display: inline-block;
height: 50px;
width: 50px;
border: 1px solid lightblue;
text-align: center;
}
.square {
background-color: lightyellow;
width: 80px;
}
.rect {
background-color: lightgreen;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<div class="square"></div>
<div class="rect"></div>
<div id="canvas"></div>
&#13;