JQuery Sortable + Bootstrap - 第1列到最后一列 - 项目消失

时间:2017-06-07 11:41:21

标签: jquery twitter-bootstrap jquery-ui jquery-ui-sortable

我正在尝试研究如何在Bootstrap v3中使用JQuery Sortable。

我有3列,我想将第1列中的项目列表拖放到第3列 - 第2列将包含一些按钮来来回移动所有项目。

然而,在拖动时,该功能有效,该项目在中间列后面消失。

我已经尝试设置列的Z-Index和正在移动的项目,但仍然没有欢乐。

这是一个基本的小提琴...... JsFiddle

$(".sortableList").sortable({
  cancel: ".fixed",
  connectWith: '.sortableList',
  distance: 6,
  opacity: 0.5
});
#available {
  background-color: #ebebeb;
  height: 200px;
}

#selected {
  background-color: #ebebeb;
  height: 200px;
}

.item {
  margin: 1px;
  background-color: #bebebe;
}

.sortPlaceholder {
  opacity: 0.25;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div id="sortContainer" class="container-fluid">
  <div class="row">
    <div class="col-xs-5 scroll-vertical">
      <div style="overflow: hidden; position: relative">
        <div id="available" class="sortableList" runat="server">
          <div class="item">Item 1</div>
          <div class="item">Item 2</div>
          <div class="item">Item 3</div>
          <div class="item">Item 4</div>
          <div class="item">Item 5</div>
        </div>
      </div>
    </div>
    <div class="col-xs-2">
      <input type="button" class="btn btn-primary" value="<<" onclick="removeAll()" />
      <input type="button" class="btn btn-primary" value=">>" onclick="addAll()" />
    </div>
    <div class="col-xs-5  scroll-vertical">
      <div style="overflow: hidden; position: relative">
        <div id="selected" class="sortableList" runat="server"></div>
      </div>
    </div>
  </div>
</div>

2 个答案:

答案 0 :(得分:1)

overflow:hidden内有一个scroll-vertical的div。您需要删除它或将其更改为可见

然后如果您需要在容器内滚动,请将overflow-y auto添加到.sortableList

请参阅下面的代码段

&#13;
&#13;
$(".sortableList").sortable({
  cancel: ".fixed",
  connectWith: '.sortableList',
  distance: 6,
  opacity: 0.5
});
&#13;
.sortableList  {
    overflow-y:auto;
}
#available {
  background-color: #ebebeb;
  height: 50px;

}

#selected {
  background-color: #ebebeb;
  height: 200px;

}

.item {
  margin: 1px;
  background-color: #bebebe;
}

.sortPlaceholder {
  opacity: 0.25;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div id="sortContainer" class="container-fluid">
  <div class="row">
    <div class="col-xs-5 scroll-vertical">
      <div style="overflow: visible; position: relative">
        <div id="available" class="sortableList" runat="server">
          <div class="item">Item 1</div>
          <div class="item">Item 2</div>
          <div class="item">Item 3</div>
          <div class="item">Item 4</div>
          <div class="item">Item 5</div>
        </div>
      </div>
    </div>
    <div class="col-xs-2">
      <input type="button" class="btn btn-primary" value="<<" onclick="removeAll()" />
      <input type="button" class="btn btn-primary" value=">>" onclick="addAll()" />
    </div>
    <div class="col-xs-5  scroll-vertical">
      <div style="overflow: visible; position: relative">
        <div id="selected" class="sortableList" runat="server"></div>
      </div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我创建了一个库,将bootstraps网格转换成拖放的东西,并保持其响应能力。 https://rosspi.github.io/gridstrap.js/