【问题标题】:Sortablejs - how can exclude element from sortingSortablejs - 如何从排序中排除元素
【发布时间】:2020-11-23 16:44:02
【问题描述】:

使用Sortable.js 我只尝试让Collapsible elements 更改它们的顺序,因此如果我将元素#1 移动到元素#2 的位置,它们不会影响它们之间的绿线。我试过filter 选项,但它只是阻止我的绿线元素是可拖动的,但我可以放置任何我想要阻止的元素来代替它。可以用这样的库吗?

【问题讨论】:

  • 有点晚了,但我遇到了类似的问题,那就是answered here。在您的情况下,它可能仍然无法正常工作——我建议您改用 SortableJS Swap Plugin

标签: sortablejs


【解决方案1】:

由于我提到使用交换,这里有一个演示可能有效(我知道它已经晚了,但记录在案)

Sortable.create(list, {
  draggable: ".list-group-item",
  filter: ".divider",
  swap: true,
  swapClass: "highlight",
  animation: 150,

});
body {
  padding: 1em;
  text-align: center;
}

.highlight {
  background-color: #f9c7c8 !important;
}

.divider {
  height: 20px;
  background: green;
  width: 3px;
  margin-left: 50%
}
<script src="https://raw.githack.com/SortableJS/Sortable/master/Sortable.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />

<div id="list" class="list-group">
  <div class="list-group-item">Item 1</div>
  <div class="divider"></div>
  <div class="list-group-item">Item 2</div>
  <div class="divider"></div>
  <div class="list-group-item">Item 3</div>
</div>

【讨论】:

    猜你喜欢
    • 2016-05-20
    • 2016-01-22
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 2012-10-24
    • 2016-02-21
    • 1970-01-01
    相关资源
    最近更新 更多