简体   繁体   English

jQuery UI Sortable 连接列表 css 问题

[英]jQuery UI Sortable connected list css issues

I am using jquery ui sortable with connected lists.我正在使用可通过连接列表排序的 jquery ui。 I have 2 problems with one most important requirement.我有一个最重要的要求有两个问题。

  1. Items goes behind the other list while dragging li.ui-splitselect-item拖动li.ui-splitselect-item落后于另一个列表
  2. Dragging item to right(when mouse is too right) creates Horizontal scroll向右拖动项目(当鼠标太右时)创建水平滚动

IMPORTANT: Lists ul.ui-splitselect-list should have overflow-y:auto;重要:列表ul.ui-splitselect-list应该有overflow-y:auto; So Header of lists stay fixed and only list items are scrolled所以列表的标题保持固定,只有列表项被滚动在此处输入图片说明

NOTE: I previous asked this question on STACKOVERFLOW but didnt notice my important requirement was missing from solution so i opened question again with clarity.注意:我之前在STACKOVERFLOW上问过这个问题,但没有注意到解决方案中缺少我的重要要求,所以我再次明确地提出了问题。

JSFIDDLE: http://jsfiddle.net/bababalcksheep/z67Td/ JSFIDDLE: http : //jsfiddle.net/bababalcksheep/z67Td/

HTML Mockup: HTML样机:

<div class="ui-splitselect ui-helper-clearfix ui-widget ui-widget-content" style="height:200px;" >
    <div class="ui-widget-content ui-splitselect-selected">
        <div class="ui-widget-header ui-helper-clearfix">
             List1
        </div>
        <ul id="sortable1"  class="ui-splitselect-list" style="height: 332px;">
            <li class="ui-splitselect-item ui-state-default">
                <a class='ui-splitselect-handle-drag'><span class='ui-icon ui-icon-carat-2-n-s'></span></a>
                <span class="ui-splitselect-handle-select">TEST-List1</span>
                <a class="ui-splitselect-handle-move" href="#"><span class="ui-icon ui-icon-plus"></span></a>
            </li>  
        </ul>
    </div>
    <div class="ui-widget-content ui-splitselect-available"  >
        <div class="ui-widget-header ui-helper-clearfix">
              List2
        </div>
        <ul id="sortable2"  class="ui-splitselect-list" style="height: 332px;">
        </ul>
    </div>
</div>

CSS: CSS:

.ui-splitselect{font-size:.8em;width:100%!important;text-align:center;margin:0 auto;padding:0}
.ui-splitselect ul{-moz-user-select:none}
.ui-splitselect .ui-widget-header{border:none;font-size:11px}
.ui-splitselect-selected{height:100%!important;float:left;border:none;width:50%;margin:0;padding:0}
.ui-splitselect-available{height:100%!important;width:49.4%;float:left;border-top:none;border-bottom:none;border-right:none;margin:0;padding:0}
.ui-splitselect-list{height:92%!important;position:relative;list-style:none;overflow:auto;margin:0;padding:0}
.ui-splitselect-item{cursor:default;line-height:20px;height:20px;font-size:11px;list-style:none;display:list-item;white-space:nowrap;overflow:hidden;margin:1px;padding:0}
.ui-splitselect-item.ui-sortable-helper{z-index:99999}
.ui-splitselect-handle-select{float:left}
.ui-splitselect-handle-drag{float:left;height:20px;border-top:0;border-bottom:0;cursor:pointer;margin:0 10px 0 5px;padding:2px 5px}
.ui-splitselect-handle-move{text-decoration:none;cursor:pointer;float:right;height:20px;border-top:0;border-bottom:0;margin:0 5px 0 10px;padding:2px 5px}

JS: JS:

 $("#sortable1, #sortable2").sortable({
     connectWith: ".ui-splitselect-list",
     containment: ".ui-splitselect",
     scroll: false,
     placeholder: "ui-state-highlight ui-splitselect-item"
 }).disableSelection();

Try adding appendTo: document.body and helper: clone options for sortable , like this:尝试为sortable添加appendTo: document.bodyhelper: clone选项,如下所示:

$("#sortable1, #sortable2").sortable({
  appendTo: document.body,
  helper: "clone",
  connectWith: ".ui-splitselect-list",
  containment: ".ui-splitselect",
  scroll: false,
  placeholder: "ui-state-highlight ui-splitselect-item"
}).disableSelection();

Js fiddle: http://jsfiddle.net/XpP25/2/ Js小提琴: http : //jsfiddle.net/XpP25/2/

Trick is in creating sorting helper that clones your original element, and then appending it to body element to resolve zIndex issues.技巧在于创建克隆原始元素的排序助手,然后将其附加到 body 元素以解决zIndex问题。 All helpers are automatically removed after stop event of draggable and sortable, so it shouldn't mess your code :)在可拖动和可排序的停止事件后自动删除所有帮助程序,因此它不应该弄乱您的代码:)

Hope it helps.希望它有帮助。

I was having a similar issue with nested sortable items.我在嵌套可排序项目方面遇到了类似的问题。 I have multiple sortable containers, that make up a grid, then widgets inside of those sortable containers.我有多个可排序的容器,它们组成一个网格,然后是这些可排序容器内的小部件。 Inside of each widget there is a nested sortable container which takes up the width and height.每个小部件内部都有一个嵌套的可排序容器,它占据宽度和高度。 Inside of the nested sortables I can have multiple nested-widgets, spanning the width of the nested sortable.在嵌套可排序对象内部,我可以有多个嵌套小部件,跨越嵌套可排序对象的宽度。

Here is how one of those sortables would look:以下是这些可排序对象之一的外观:

<div class="sortable">
  <div class="widget">
    <div class="nested-sortable">
      <div class="nested-widget"></div>
    </div>
  </div>
</div>

Now, once I started dragging my nested sortable item, it would go behind every outer widget except for the one containing it.现在,一旦我开始拖动嵌套的可排序项,它将位于每个外部小部件的后面,除了包含它的小部件。 I tried changing the z-index of the items on sort start and no luck.我尝试在排序开始时更改项目的 z-index,但没有运气。 I needed something like jQuery UI's Draggable stack option, which "stacks" the currently dragged item over all other items of the same class.我需要类似 jQuery UI 的 Draggable stack选项,它将当前拖动的项目“堆叠”在同一类的所有其他项目上。

Here is jQuery UI's draggable stack function on github at line 800.这是GitHub上第 800 行的 jQuery UI 的可拖动堆栈函数。

So, my friend and I modified that code a bit, and called it on the "outer" widget.所以,我和我的朋友稍微修改了该代码,并在“外部”小部件上调用它。

$.fn.stack = function () {
    // where $(this) == '.widget'
    var o = $(this).closest('.sortable').siblings('.sortable').find('.widget');

    // create an array of all the widgets
    var group = $(o).sort(function(a,b) {
        // compare the each set of widgets
        return (parseInt($(a).css("z-index"),10) || 1) - (parseInt($(b).css("z-index"),10) || 1);
    });
    if (!group.length) { return; }

    var min = parseInt($(group[0]).css('z-index')) || 1; // first widget's z-index
    $(group).each(function(i) {
        // increase each widget's z-index by min + $(this) widget's index value
        $(this).css('z-index',  min + i);
    });

    // make currently dragged widget's z-index min + length of group
    $(this[0]).css('z-index', min + group.length);
}

Then call in sortable start:然后调用可排序的开始:

$('.nested-sortable').sortable({
    start: function(event, ui) {
        $(this).closest('.widget').stack();
    }
});

Here is my codepen for reference: Nested Grid System这是我的代码笔供参考:嵌套网格系统

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

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