Чтобы это исправить, вам нужно установить z-index
для элементов .item
выше, чем для элементов #slotN
.По умолчанию они установлены на 1000
.
Также обратите внимание, что в вашем JS и CSS много ненужных повторений, когда вы используете уникальные идентификаторы элементов.Вместо этого поместите в них общие классы, а затем выберите их.Попробуйте это:
$(function() {
const correct = [{
slot: "slot1",
item: "item3"
}, {
slot: "slot2",
item: "item5"
}, {
slot: "slot3",
item: "item2"
}, {
slot: "slot4",
item: "item7"
}, {
slot: "slot5",
item: "item7"
}, {
slot: "slot6",
item: "item4"
}];
var answers = [{
slot1: ""
}, {
slot2: ""
}]
$(".item").draggable({
cursor: "pointer"
});
$('.slot').droppable({
drop: handleDropEvent
});
});
function handleDropEvent(event, ui) {
var item = ui.draggable;
var slot = $(this).attr('id');
ui.draggable.position({ of: $(this),
my: 'left top',
at: 'left top'
});
}
.content {
position: relative;
}
.item, .slot {
margin: 0;
display: inline-block;
margin: 10px;
}
.item {
width: 65px;
height: 65px;
padding: 5px;
float: left;
margin: 0 10px 10px 0;
font-size: 0.9em;
display: inline-block;
z-index: 10001;
}
.item1 { background: darksalmon; }
.item2 { background: cyan; }
.item3 { background: darkgreen; }
.item4 { background: lightpink; }
.item5 { background: lightgreen; }
.item6 { background: brown; }
.item7 { background: purple; }
.item8 { background: orange; }
.dash {
position: relative;
}
.slot {
background: lightgrey;
border: solid;
height: 75px;
width: 75px;
position: absolute;
}
#slot1 {
top: 23px;
left: 37px;
}
#slot2 {
top: 23px;
left: 129px;
}
#slot3 {
top: 55px;
left: 445.5px;
}
#slot4 {
top: 233px;
left: 571.2px;
}
#slot5 {
top: 233px;
left: 656px;
}
#slot6 {
top: 233px;
left: 742px;
}
#slot7 {
top: 233px;
left: 828px;
}
#slot8 {
top: 197.5px;
left: 9px;
}
<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 class="content">
<div>
<div id="item1" class="item item1 ui-widget-content"></div>
<div id="item2" class="item item2 ui-widget-content"></div>
<div id="item3" class="item item3 ui-widget-content"></div>
<div id="item4" class="item item4 ui-widget-content"></div>
<div id="item5" class="item item5 ui-widget-content"></div>
<div id="item6" class="item item6 ui-widget-content"></div>
<div id="item7" class="item item7 ui-widget-content"></div>
<div id="item8" class="item item8 ui-widget-content"></div>
<br><br><br><br><br><br>
<div class="dash">
<img src="image1.png">
<div id="slot1" class="slot ui-widget-header">
<p>holder</p>
</div>
<div id="slot2" class="slot ui-widget-header">
<p>holder</p>
</div>
<div id="slot3" class="slot ui-widget-header">
<p>holder</p>
</div>
<div id="slot4" class="slot ui-widget-header">
<p>holder</p>
</div>
<div id="slot5" class="slot ui-widget-header">
<p>holder</p>
</div>
<div id="slot6" class="slot ui-widget-header">
<p>holder</p>
</div>
<div id="slot7" class="slot ui-widget-header">
<p>holder</p>
</div>
<div id="slot8" class="slot ui-widget-header">
<p>holder</p>
</div>
</div>
</div>