jQuery UI 可拖动元素始终位于顶部

发布于 2024-11-15 04:41:40 字数 211 浏览 3 评论 0原文

我需要从左侧区域拖动的元素始终位于顶部。当我第一次从左侧区域拖动它们时,它们是这样的,但是如果我将它们放入框 2,然后决定拖动到框 1,我拖动的项目会出现在框 1 下方。

感到困惑吗?这是我正在谈论的内容的DEMO

是的,我添加了 zIndex ——没有帮助。

I need to have elements that are dragged from left-hand side area to be always on top. And they are when I first drag them from left area, however if I drop them into Box 2 and then decide to drag to Box 1, the item I drag appears below Box 1.

Confused? Here's DEMO of what I'm talking about.

Yes, I have added zIndex -- did not help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩发小公举 2024-11-22 04:41:40

看起来您正在做一些编辑。 :)

解决方案是将两个框设置为相同的 z-index,然后使用“start”事件降低同级框(卡片未覆盖的框)的 z-index。 “停止”事件应该使它们再次相等。当然,可拖动本身需要更高的 z-index。

您还可以尝试堆栈选项

编辑:工作示例。 请注意,它实际上是可拖动的 drop< /code> 需要再次将 z 索引设置为相等的事件。

需要进行这些更改(当然,省略代码中的星号):

dragdrop-client.js

// make the new card draggable
    newCard.draggable({
        zIndex: 2500,
        handle: ".card",
        stack: ".card",
        revert: "invalid",
        start: function() {
            $(this).effect("highlight", {}, 1000);
            $(this).css( "cursor","move" );
                **var $par = $(this).parents('.stack');
                if ($par.length == 1) {
                    console.log('in stack');
                    $par.siblings().css('z-index', '400');
                }**
        },
        stop: function() {
            $(this).css("cursor","default");
                $(".stack").css('z-index', '500');
        }
    });

// make the new stack droppable
    newStack.droppable({
        tolerance: "intersect",
        accept: ".card",
        greedy: true,
        drop: function(event, ui) {
            **$(".stack").css('z-index', '500');**
            card = ui.draggable;
            putCardIntoStack(card,stackId);
        }
    }); 

dragdrop-client.css

.stack {
    width: 300px;
    border: 1px dashed #ccc;
    background-color: #f5f5f5;
    margin: 10px;
    float:left;
    **z-index:500;**
}

Looks like you are doing some editing. :)

The solution is set the two boxes to the same z-index, and then lower the z-index of the sibling (the box the card is NOT over) using the "start" event. The "stop" event should set them equal again. Of course the draggable itself needs a higher z-index.

You can also try the stack option.

EDIT: Working example. Note that its actually the draggable drop event that needs to set the z-indexs equal again.

You'll need to make these changes (omit asterisks in your code, of course):

In dragdrop-client.js

// make the new card draggable
    newCard.draggable({
        zIndex: 2500,
        handle: ".card",
        stack: ".card",
        revert: "invalid",
        start: function() {
            $(this).effect("highlight", {}, 1000);
            $(this).css( "cursor","move" );
                **var $par = $(this).parents('.stack');
                if ($par.length == 1) {
                    console.log('in stack');
                    $par.siblings().css('z-index', '400');
                }**
        },
        stop: function() {
            $(this).css("cursor","default");
                $(".stack").css('z-index', '500');
        }
    });

// make the new stack droppable
    newStack.droppable({
        tolerance: "intersect",
        accept: ".card",
        greedy: true,
        drop: function(event, ui) {
            **$(".stack").css('z-index', '500');**
            card = ui.draggable;
            putCardIntoStack(card,stackId);
        }
    }); 

In dragdrop-client.css

.stack {
    width: 300px;
    border: 1px dashed #ccc;
    background-color: #f5f5f5;
    margin: 10px;
    float:left;
    **z-index:500;**
}
阳光下的泡沫是彩色的 2024-11-22 04:41:40

当动态插入元素时,我会执行two7s_clash 建议的拖放操作。我们在画布上插入了一些元素,然后我们想要将其拖放到所有内容上:

start: function(e) { $('element').css('z-index', -1)}
stop:  function(e) { $('element').css('z-index', 0)}

I do what two7s_clash recommends for my drag-drop when elements are inserted dynamically. We have some elements being inserted over a canvas and then we want to drag n drop over everything:

start: function(e) { $('element').css('z-index', -1)}
stop:  function(e) { $('element').css('z-index', 0)}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文