【问题标题】:stack option for a draggable div on jquery-ui 1.9.2 resets the element z-indexjquery-ui 1.9.2 上可拖动 div 的堆栈选项重置元素 z-index
【发布时间】:2013-01-28 15:45:46
【问题描述】:

我有几个(动态生成的)div,它们的 z-index 在 css 中设置为 120:

.plugin {
        position: absolute;
        z-index: 120;
    }

它们包含一个标题(位于顶部)和一个画布:

.plugin_title {
        font-size: 13px;
        color: rgba(255, 255, 255, 0.9);
        font-family: arial;
        background-color: #300;
        z-index: 150;
    }
.plugin_canvas {
        position: relative;
        background-color: black;
        border: 1px solid #300;
        border-bottom-right-radius: 5px;
        z-index: 120;
    }

当我创建它们时,我会这样做:

var div = $( '<div class="plugin ' + audioclass + '" id="'+ id + '"</div>').width(width + 2).height(height + 2);
var ctx = $( '<canvas class="plugin_canvas" width="' + width + '" height="'+ height + '" />', {width: width, height: height} );
var title = $( '<div class="plugin_title"> ' +name + ' </div>');
title.appendTo(div);
ctx.appendTo(div);
div.appendTo('#plugin_area');

然后调用jsplumb.draggable 使它们可拖动(jsplumb 只是调用jquery 的.draggable()

jsPlumb.draggable(div, {cursor: "move", handle: title, opacity: 0.9, stack: ".plugin", scroll: true})

问题是当我拖动一个 .plugin div 时,它的 z-index 被重置为 1(并且每次拖动它时都会增加,因为 stack 选项)。相反,我希望 z-index 从 120(.plugin div 的原始 z-index 值)开始并从该值递增。

jqueryui 1.7 有一个min 参数用于stack 选项。在jqueryui 1.9.2(我正在使用的版本)中,您只能指定一个选择器,并且据我所知,堆叠应该从元素预先存在的z-index开始。相反,它似乎从 1 开始任意重新开始。我错过了什么?

(jsplumb: 1.3.16, jqueryui: 1.9.2, jquery: 1.8.1。请注意我不能回滚到旧版本的 jquery-ui)

【问题讨论】:

    标签: css jquery-ui z-index draggable jsplumb


    【解决方案1】:

    解决方法

    $(".plugin").each(function() {
                // always use a radix when using parseInt
                var index_current = parseInt($(this).css("zIndex"), 10);
                if((20 - index_current) > 0) {
                    $(this).css("zIndex", 20 + index_current);
                }
            });
    

    还在 jqueryUI here 中报告并修复了错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-10
      • 2011-06-17
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多