简体   繁体   English

jQuery UI Sortable - 多连接列表拖动

[英]jQuery UI Sortable - Multi Connected List Drag

Using jQuery UI Sortable, there is an option to have the sortable item container scroll when an item is dragged .使用 jQuery UI Sortable,可以选择在拖动项目时让可排序项目容器滚动

I have multiple sortable lists connected in separate containers with max heights and overflow scrolls:我有多个可排序列表连接在具有最大高度和溢出滚动的单独容器中:

<div class="list">
  <div class="item">A1</div>
  <div class="item">A2</div>
  <div class="item">A3</div>
  <div class="item">A4</div>
  <div class="item">A5</div>
</div>

<div class="list">
  <div class="item">B1</div>
  <div class="item">B2</div>
  <div class="item">B3</div>
  <div class="item">B4</div>
  <div class="item">B5</div>
</div>

I need to be able to scroll each container when items are dragged between them.当项目在它们之间拖动时,我需要能够滚动每个容器。

Currently, dragging only scrolls the parent container - we need it to be able to scroll connected list containers.目前,拖动只滚动父容器 - 我们需要它能够滚动连接的列表容器。

See this codepen for basic setup: http://codepen.io/typ90/pen/pymOdV有关基本设置,请参阅此代码笔: http ://codepen.io/typ90/pen/pymOdV

I've tried using the helper option on sortable to clone the item and append to other containers as it's dragged around with no luck.我已经尝试使用 sortable 上的 helper 选项来克隆项目并附加到其他容器,因为它被拖到了没有运气的地方。

Any ideas?有什么想法吗?

Just add the code below to your sortable configuration section:只需将以下代码添加到您的sortable配置部分:

over: function (e, ui) {
  $(ui.sender).sortable('instance').scrollParent = $(e.target)
}

It will be like that:它会是这样的:

$('.list').sortable({
  items: '.item',
  connectWith: '.list',
  over: function (e, ui) {
    $(ui.sender).sortable('instance').scrollParent = $(e.target)
  }
});

Solution with helper and clone带助手和克隆的解决方案

$('.list').sortable({
  connectWith: '.list',
  placeholder: 'ui-state-highlight',
  helper: function (event, element) {
    return element.clone().appendTo($('.connectedSortable').not(element.parent()));
  }
});

in my case the use of only option "clone" was not possible because of z-index issue with sort element.在我的情况下,由于排序元素的 z-index 问题,无法仅使用选项“克隆”。

credit goes to https://stackoverflow.com/users/2117156/jamie-barker信用转到https://stackoverflow.com/users/2117156/jamie-barker

The accepted answer was not the solution in my case with the same problem as the OP.在我的情况下,接受的答案不是与 OP 存在相同问题的解决方案。 I was getting errors with the accepted answer.我在接受的答案中遇到错误。

However, it was very close.然而,它非常接近。 I simply needed to check that ui.sender was a truthy value.我只需要检查ui.sender是否为真值。

$('.list').sortable({
  items: '.item',
  connectWith: '.list',
  over: function (e, ui) {
    if (ui.sender) {
      $(ui.sender).sortable('instance').scrollParent = $(e.target)
    }
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM