Drag & Drop + Clone
by KapulaGabor
HTML
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<div class="col-1">
<div class="mozgat f-szurke f75x30">
<p>F 75x30</p>
</div>
<div class="mozgat f-szurke f75x45">
<p>F 75x45</p>
</div>
</div>
<p class="clr"> </p>
<div id="osszerakas">
<div id="snaptarget1" class="bal-oszlop tapad bal"></div>
<div id="snaptarget2" class="kozepso-oszlop tapad bal"></div>
<div id="snaptarget3" class="jobb-oszlop tapad jobb"></div>
</div>
CSS
* {
padding: 0;
margin: 0;
}
.clr {
clear: both;
}
body {
background-color: #4A5157;
font-family: sans-serif;
}
.col-1, .col-2, .col-3 {
position: relative;
float: left;
margin-right: 7px;
}
.mozgat {
cursor: move;
margin-bottom: 7px;
}
.f75x30 {
width: 150px;
height: 60px;
line-height: 60px;
border-radius: 2px;
}
.f75x45 {
width: 150px;
height: 90px;
line-height: 90px;
border-radius: 2px;
}
.f75x30 p, .f75x45 p {
font-family: sans-serif;
font-size: 18px;
color: Gainsboro;
text-align: center;
text-shadow: 0px 1px 1px rgba(0, 0, 0, .4);
}
.jobb {
float: right;
}
.bal {
float: left;
}
.f-szurke {
background-color: #999999;
}
#osszerakas {
margin: 0 auto;
width: 788px;
height: 500px;
}
.item {
cursor: move;
border: 1px solid #333;
border-collapse: collapse;
}
#snaptarget1, #snaptarget2, #snaptarget3 {
position: relative;
border: 1px solid #4A5157;
border-collapse: collapse;
}
#snaptarget1 {
width: 210px;
height: 369px;
}
#snaptarget2 {
width: 362px;
height: 276px;
}
#snaptarget3 {
width: 210px;
height: 369px;
}
.snaptarget-hover {
background-color: #616A72;
}
JavaScript
$(function () {
$(".mozgat").draggable({
helper: "clone",
appendTo: "body",
revert: "invalid",
scroll: false
});
$("#snaptarget1,#snaptarget2,#snaptarget3").droppable({
accept: ".mozgat",
activeClass: "snaptarget-hover",
drop: function (event, ui) {
$(this).append($(ui.draggable).clone());
$("#snaptarget1 .mozgat,#snaptarget2 .mozgat,#snaptarget3 .mozgat").addClass("item");
$(".item").removeClass("ui-draggable mozgat");
$(".item").draggable({
containment: "#osszerakas",
grid: [1, 1],
snap: ".tapad",
snapMode: "inner",
stack: ".item"
});
}
});
});