【问题标题】:JQuery Sortable + Bootstrap - 1st column to last column - item vanishesJQuery Sortable + Bootstrap - 第一列到最后一列 - 项目消失
【发布时间】:2017-11-08 17:57:03
【问题描述】:

我正在尝试研究如何将 JQuery Sortable 与 Bootstrap v3 一起使用。

我有 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>

【问题讨论】:

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


    【解决方案1】:

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

    如果你需要在容器内滚动,添加overflow-y auto到.sortableList

    见下面的sn-p

    $(".sortableList").sortable({
      cancel: ".fixed",
      connectWith: '.sortableList',
      distance: 6,
      opacity: 0.5
    });
    .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;
    }
    <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>

    【讨论】:

    • 溢出:隐藏是另一个问题的解决方法。我需要能够垂直滚动项目列表...但是设置 overflow-y: scroll 会导致问题,即被拖动的项目会导致包含 div 无限地水平滚动。
    【解决方案2】:

    我创建了一个库来将引导网格变成拖放的东西并保持它的响应能力。 https://rosspi.github.io/gridstrap.js/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-05
      • 1970-01-01
      • 2013-11-09
      • 1970-01-01
      相关资源
      最近更新 更多