【问题标题】:jQuery UI Sortable connected list css issuesjQuery UI 可排序连接列表 css 问题
【发布时间】:2019-11-22 01:58:31
【问题描述】:

我正在使用可通过连接列表排序的 jquery ui。我有 2 个问题,其中一个最重要的要求。

  1. 拖动li.ui-splitselect-item时,项目位于另一个列表的后面
  2. 向右拖动项目(当鼠标太右时)创建水平滚动

重要提示:列表 ul.ui-splitselect-list 应该有 overflow-y:auto; 所以列表的标题保持固定 并且仅滚动列表项

注意: 我之前在STACKOVERFLOW 上问过这个问题,但没有注意到解决方案中缺少我的重要要求,所以我再次清楚地打开了问题。

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

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:

.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:

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

【问题讨论】:

    标签: javascript jquery css jquery-ui jquery-ui-sortable


    【解决方案1】:

    尝试为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 小提琴:http://jsfiddle.net/XpP25/2/

    诀窍在于创建克隆原始元素的排序助手,然后将其附加到正文元素以解决zIndex 问题。在可拖动和可排序的停止事件后,所有助手都会自动删除,所以它不应该弄乱你的代码:)

    希望对你有帮助。

    【讨论】:

    • 当我在你的 JSFIDDLE 中拖动元素时,它似乎松散了字体样式。我该如何解决这个Thankx
    • 我认为这是原始 jquery ui css 的东西。克隆总是有 ui-draggable 和 ui-draggable-dragging 类,但老实说,除了与 css 中的这些类相关联的光标之外,我不认识任何其他东西。对不起。我会努力寻找解决办法!
    【解决方案2】:

    我在嵌套可排序项目方面遇到了类似的问题。我有多个可排序的容器,它们组成一个网格,然后是这些可排序容器内的小部件。每个小部件内部都有一个嵌套的可排序容器,它占据了宽度和高度。在嵌套的 sortable 内部,我可以有多个嵌套的小部件,跨越嵌套的 sortable 的宽度。

    这是其中一个可排序的外观:

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

    现在,一旦我开始拖动嵌套的可排序项,它就会出现在每个外部小部件的后面,除了包含它的小部件。我尝试在排序开始时更改项目的 z-index,但没有运气。我需要类似 jQuery UI 的 Draggable stack 选项,它将当前拖动的项目“堆叠”在同一类的所有其他项目上。

    这是 jQuery UI 在第 800 行的 github 的可拖动堆栈函数。

    所以,我和我的朋友稍微修改了该代码,并在“外部”小部件上调用它。

    $.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);
    }
    

    然后在 sortable start 中调用:

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

    这是我的代码笔供参考:Nested Grid System

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-14
      • 1970-01-01
      • 1970-01-01
      • 2015-07-23
      • 2011-02-11
      • 2013-05-14
      • 1970-01-01
      相关资源
      最近更新 更多