jquery droppable/html5 api - 如何使元素可拖放

jquery droppable/html5 api - how to make element droppable and draggable

我知道如何制作一个可拖动且可以放置在某个放置区的 emelent,但是我怎样才能使这个可放置的元素也可以拖动到另一个放置区?因此,让图像我有一个可放置的容器,在这里我可以四处移动元素(可以说是垂直的),另外我可以将一些元素放入这些可拖动的元素中并在 em 内四处移动它们。可能吗?

您可以使用 class 作为容器,您可以在其中对可拖动 and/or 可排序 div 元素进行排序或删除。

然后您可以复制 class,例如 class dropzone。这样就可以将元素从一个 div 拖到另一个,并且可以对它们进行排序。

片段:

$(".colzone").sortable({
  connectWith: ".colzone",
  update: function(event, ui) {},
  placeholder: "dashed2"
});

$(".dropzone").sortable({
  connectWith: ".dropzone",
  update: function(event, ui) {},
  placeholder: "dashed"
});
.colzone {
  margin: 10px;
  border: green 2px solid;
  height: 100%;
  background-color: #eeeeee;
}

.colpick {
  background-color: orange;
  border: yellow 2px solid;
  cursor: pointer;
}

.dropzone {
  margin: 10px;
  border: red 2px solid;
  width: 100px;
  height: 250px;
  background-color: #ededed;
}

.grid-users {
  background: #f5f5f5;
  padding-bottom: 5px;
  padding-top: 5px;
  padding-right: 0px;
  padding-left: 0px;
  cursor: move;
  border: #000 1px solid;
  text-align: center;
  font-weight: bold;
}

.dashed {
  border: 2px dashed #999;
  background: #ede8e8;
  height: 35px;
}

.dashed2 {
  border: 2px dashed #999;
  background: #ede8e8;
  height: 295px;
  width: 140px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<div class="container">
  <div class="colzone row">

    <!-- COLUMN 1 -->
    <div class="colpick">
      <div style="text-align: center; font-weight: bold;">
        COLUMN 1
      </div>
      <div class="dropzone">
        <div id="team-1" class="grid-users">TEAM 1</div>
        <div id="team-2" class="grid-users">TEAM 2</div>
        <div id="team-3" class="grid-users">TEAM 3</div>
        <div id="team-4" class="grid-users">TEAM 4</div>
      </div>
    </div>

    <!-- COLUMN 2 -->
    <div class="colpick">
      <div style="text-align: center; font-weight: bold;">
        COLUMN 2
      </div>
      <div class="dropzone">
        <div id="team-5" class="grid-users">TEAM 5</div>
        <div id="team-6" class="grid-users">TEAM 6</div>
      </div>
    </div>

    <!-- COLUMN 3 -->
    <div class="colpick">
      <div style="text-align: center; font-weight: bold;">
        COLUMN 3
      </div>
      <div class="dropzone"></div>
    </div>

  </div>
</div>