Я не спал всю ночь и пытался делать это в течение 13 часов, и, наконец, мне это удалось.
var invalid = false;
$(".inventory-list div, .account-list div").sortable({
placeholder: " ",
connectWith: ".inventory-list div, .account-list div",
containment: ".container",
opacity: 0.7,
zIndex: 9999,
cursor: "pointer",
scroll: false,
create: function( event, ui ) {
if ( !$(this).is(':empty') ){
$(this).addClass("item-disabled");
}
},
over: function( event, ui ) {
if( this !== event.currentTarget ){
if($(event.target).hasClass("item-disabled") ){
invalid = true;
}
}
},
over: function(event,ui){
invalid = false;
if( this !== event.currentTarget ){
if( $(event.target).hasClass("item-disabled") ){
invalid = true;
}
}
},
remove: function( event, ui ) {
if(invalid != true){
$(this).removeClass("item-disabled");
}
},
receive: function( event, ui ) {
if(invalid == true){
ui.sender.sortable("cancel");
}
$(this).addClass("item-disabled");
}
});
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
body{
background: #f5f5f5;
font-family: Arial, sans-serif;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
.card {
width: 260px;
display: inline-grid;
border: 2.5px solid rgb(8 208 255);
background: #ffffff;
position: relative;
color: rgb(8 208 255);
border-radius: 10px;
font-weight: bold;
margin-right: 10px;
margin-bottom: 20px;
}
.card-title{
padding: 10px;
border-bottom: 4px solid rgb(8 208 255);
background: #08d0ff;
color: white;
text-align: center;
}
.icon {
background-size: 60px;
background-position: center center;
background-repeat: no-repeat;
display: flex;
height: 50px;
width: 50px;
flex: 1 0 27%;
position: relative;
}
.c1{
background-image: url('https://image.flaticon.com/icons/svg/927/927593.svg');
}
.c2{
background-image: url('https://image.flaticon.com/icons/svg/859/859205.svg');
}
.c3{
background-image: url('https://image.flaticon.com/icons/svg/148/148919.svg');
}
.c4{
background-image: url('https://image.flaticon.com/icons/svg/148/148838.svg');
}
.c5{
background-image: url('https://image.flaticon.com/icons/svg/138/138292.svg');
}
.c6{
background-image: url('https://image.flaticon.com/icons/svg/148/148808.svg');
}
.inventory-list{
display: flex;
flex-wrap: wrap;
padding: 5px;
}
.account-list{
display: flex;
flex-wrap: wrap;
padding: 5px;
}
.account-list, .inventory-list{
min-height: 315px;
background-color: rgb(240 253 255);
border-radius: 10px;
}
.slot{
flex: 1 0 27%;
margin: 5px;
height: 65px;
width: 65px;
border: 2px solid #59dfff;
justify-content: center;
display: flex;
align-items: center;
background: white;
}
.container{
text-align: center;
padding-top: 20px;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Inventory System</title>
<meta name="theme-color" content="#08d0ff" />
<meta name="msapplication-navbutton-color" content="#08d0ff" />
<meta name="apple-mobile-web-app-status-bar-style" content="#08d0ff" />
</head>
<body>
<div class="container">
<div class="card">
<div class="card-title">Inventory</div>
<div class="inventory-list">
<div class="slot"><span class="icon c1"></span></div>
<div class="slot"><span class="icon c2"></span></div>
<div class="slot"><span class="icon c3"></span></div>
<div class="slot"><span class="icon c4"></span></div>
<div class="slot"><span class="icon c5"></span></div>
<div class="slot"><span class="icon c6"></span></div>
<div class="slot"></div>
<div class="slot"></div>
<div class="slot"></div>
</div>
</div>
<div class="card">
<div class="card-title">Account</div>
<div class="account-list">
<div class="slot"></div>
<div class="slot"></div>
<div class="slot"></div>
<div class="slot"></div>
<div class="slot"></div>
<div class="slot"></div>
<div class="slot"></div>
<div class="slot"></div>
<div class="slot"></div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
</body>
</html>