jQuery UI Droppable:如何使其生效?

发布于 2024-09-28 21:42:00 字数 527 浏览 0 评论 0原文

这个问题中,当鼠标移动时,可拖动对象是动态创建的输入要拖动的元素。

我想做同样的事情,但是使用 droppables :决定是否仅当拖动的元素到达其上方时才使元素可放置。我确信这是可能的,但经过一番研究后,我无法做到。

我尝试过类似的事情,但失败了:

jQuery.fn.liveDroppable = function (opts) {
    this.live("mouseover", function() {
        if (!$(this).data("livedropinit")) {
            $(this).data("livedropinit", true).droppable(opts);
            $(this).trigger('dropover');
        }
    });
};

In this question, draggables are created on the fly, when the mouse enters the element to drag.

I'd like to do the same kind of thing, but with droppables : decides whether to make the element droppable only when the dragged element arrives over it. I'm sure it's possible but after a bit of research, I couldn't make it.

I tried things like this, but failed:

jQuery.fn.liveDroppable = function (opts) {
    this.live("mouseover", function() {
        if (!$(this).data("livedropinit")) {
            $(this).data("livedropinit", true).droppable(opts);
            $(this).trigger('dropover');
        }
    });
};

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

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

发布评论

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

评论(2

我通过使用 这篇文章< 中描述的方法将其绑定到 JQuery 来实现此目的/a> 可拖动。唯一的问题是,我目前正在调查的嵌套 droppable 似乎存在问题。这是修改后的版本。我不得不将其更改为“mouseenter”。

(function ($) {
       $.fn.liveDroppable = function (opts) {
          this.live("mouseenter", function() {
             if (!$(this).data("init")) {
                $(this).data("init", true).droppable(opts);
             }
          });
       };
}(jQuery));

现在不要这样称呼它:

$(selector).droppable({opts});

...只需使用:

$(selector).liveDroppable({opts})

I got this to work by binding it to JQuery using the methods described on this post for draggable. The only problem is that it seems to have an issue on nested droppables which I am currently investigating. Here's the modified version. I had to change it to "mouseenter".

(function ($) {
       $.fn.liveDroppable = function (opts) {
          this.live("mouseenter", function() {
             if (!$(this).data("init")) {
                $(this).data("init", true).droppable(opts);
             }
          });
       };
}(jQuery));

Now instead of calling it like:

$(selector).droppable({opts});

...just use:

$(selector).liveDroppable({opts})
酒废 2024-10-05 21:42:00

这对你有用吗?这是 .hover();功能。不确定你是否已经尝试过。
http://api.jquery.com/hover/

Would this work for you? It's the .hover(); function. Not sure if you've tried it yet.
http://api.jquery.com/hover/

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