jQuery droppable - 如何在短时间内对悬停做出反应?

发布于 2024-12-11 06:18:55 字数 339 浏览 0 评论 0原文

我正在使用 jQuery Draggable/droppable 将(div)从一个列表拖到另一个列表。两个列表都有固定数量的列表项,并且列表项本身可以为空或已包含 div。

我正在将 div 拖到列表项。如果列表项已经包含一个 div,那么我希望将该 div 下推到其下方的列表项 - 以便为我正在拖动的 div 让路。我可以通过 droppable 中的“over”事件来做到这一点。但我希望只有在用户暂停一段时间(比如 0.5 秒)之后才会发生这种情况。我该怎么做?

另外,如果用户决定不掉落,那么我希望移位的物品返回到其原始位置。再说一遍,实现这一目标最简单的方法是什么?

感谢您的帮助

威廉

I am using jQuery draggable/droppable to drag (divs) from one list to another. Both lists have a fixed number of list items, and the list items themselves and can either be empty or already contain a div.

I am dragging a div to a list item. If the list item already contains a div then I would like that div to be pushed down to the list item below it - so as to make way for the div I am dragging. I can do this with the "over" event in droppable. But I would like this to happen only after the user has paused there for a cetain period of time, say 0.5 second. How can I do this?

Also, if the user decides not to drop then I would like the displaced item to come back to its original position. Again, what would be the easiest of accomplishing that?

Thanks for your help

William

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

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

发布评论

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

评论(1

哥,最终变帅啦 2024-12-18 06:18:55

我只是碰巧在做类似的事情。就我而言,我使用的是 treeTable 插件。如果一棵倒塌的树悬停了一段时间,我想展开它。这是我到目前为止所拥有的。我今天正好在做这件事。请注意使用超时来延迟操作。

var timeout = null;
var clear = function() {
    if (timeout) {
        clearTimeout(timeout);
        timeout = null;
    }
}

$(".selector").droppable({
    over: function(e, ui) {
        if (! $(this).is("expanded")) {
            clear();
            timeout = setTimeout(function() {
                $(this).expand();
                timeout = null;
            }, 1000);
        }
    }
    , out: clear
    , drop: function(e, ui) {
        clear();
        ...
    }
});

我仍然有这个问题。一个分支展开后,其下方的行将被下推,为展开的分支腾出空间。我还没有放下,所以我将鼠标悬停在扩展分支中的第一个新元素上。问题是这个元素没有得到hoverClass,被推到新分支下面的第一个元素得到了它。就像 jquery 没有意识到它被向下移动了一样。根据您的描述,我想您很可能会遇到这个问题。

我使用的是 jquery-1.4.2,但后来我更新到 jquery-1.6.4,看看是否可以解决问题。两个版本都表现出相同的行为。另外,我在 Chrome 14.0.835.202、Opera 11.52、Firefox 3.6.23 和 IE7.0.5730.13 中对此进行了测试。它们都以同样的方式发生。所以,要么是 jquery 有 bug,要么是我做了一些事情导致了这个问题。

关于你的第二个问题。我不确定我完全理解你要追求什么。您是否正在寻找

I just happen to be doing something similar. In my case, I am using the treeTable plugin. I want to expand a collapsed tree if it is hovered for some amount of time. Here is what I have so far. I just happen to be working on this today. Note the use of a timeout to delay the operation.

var timeout = null;
var clear = function() {
    if (timeout) {
        clearTimeout(timeout);
        timeout = null;
    }
}

$(".selector").droppable({
    over: function(e, ui) {
        if (! $(this).is("expanded")) {
            clear();
            timeout = setTimeout(function() {
                $(this).expand();
                timeout = null;
            }, 1000);
        }
    }
    , out: clear
    , drop: function(e, ui) {
        clear();
        ...
    }
});

I'm still having a problem with this. After one branch gets expanded, the rows below it get pushed down to make room for the expanded branch. I haven't dropped yet and so I go hover over the first new element in the expanded branch. The problem is that this element does not get the hoverClass, the first element that got pushed down below the new branch gets it. It is like jquery doesn't figure out that it got moved down. I imagine that you are likely to encounter this problem given what you've described.

I was on jquery-1.4.2 but then I updated to jquery-1.6.4 to see if that would fix the problem. Both versions exhibit the same behavior. Also, I tested this in Chrome 14.0.835.202, Opera 11.52, Firefox 3.6.23 and IE7.0.5730.13. It happens the same way in all of them. So, either jquery has a bug or I've done something to cause this.

About your second question. I'm not sure I completely understand what you're going after. Are you looking for the

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文