使 jQuery droppable 接受来自使用 connectWith 的可排序项的项目

发布于 2024-09-28 11:17:24 字数 412 浏览 8 评论 0原文

我有一个可排序列表,它使用 connectWith 确保它只能在其自己的列表类型中排序。

现在,我正在尝试制作一个可放置的垃圾桶元素,当对项目进行排序时,该元素会出现在视口底部。该元素位于列表的上下文之外,并且仅删除放置在其上的任何元素。如果您熟悉的话,所需的功能与从 Android 手机桌面删除快捷方式相同。

问题是,虽然我的垃圾桶是一个接受 '*' 的 droppable,但我的 sortable 只被告知 connectWith 其他 '.dropZone' 项目,这意味着我无法将任何可排序元素导致垃圾元素上出现悬停状态。

我尝试过在 start 事件上将每个可排序项变成可拖动项,但当然我没有在确切的时刻拖动该可拖动项,因此它没有被激活。是否可以同时满足这两个要求,还是我必须手动检测垃圾桶悬停?

I've got a sortable list which is using connectWith to ensure it can only be sorted within its own types of list.

Now I'm trying to make a droppable trash can element that appears at the bottom on the viewport when an item is being sorted. This element is outside the context of the lists and simply deletes any element that is dropped on it. The desired functionality is identical to deleting a shortcut from the desktop of an Android phone, if you are familiar with that.

The problem is, although my trash can is a droppable which accepts '*', my sortable is told only to connectWith other '.dropZone' items only, which means I cannot get any of my sortable elements to cause a hover state on the trash element.

I've tried making each sortable into a draggable on the start event, but of course I'm not dragging that draggable at the exact moment and so it's not activated. Is it possible to satisfy both requirements or am I going to have to detect the trash can hover manually?

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

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

发布评论

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

评论(2

亚希 2024-10-05 11:17:24

由于 connectWith 接受选择器,因此您可以为其提供一个选择器,以选择其他连接的列表和垃圾箱。

$("#sortable1, #sortable2").sortable({
    connectWith: '.connectedSortable, #trash'
}).disableSelection();

$("#trash").droppable({
    accept: ".connectedSortable li",
    hoverClass: "ui-state-hover",
    drop: function(ev, ui) {
        ui.draggable.remove();
    }
});

示例: http://jsfiddle.net/petersendidit/YDZJs/1/

Since connectWith accepts a selector, you can provide it a selector that selects both the other connected lists and your trash can.

$("#sortable1, #sortable2").sortable({
    connectWith: '.connectedSortable, #trash'
}).disableSelection();

$("#trash").droppable({
    accept: ".connectedSortable li",
    hoverClass: "ui-state-hover",
    drop: function(ev, ui) {
        ui.draggable.remove();
    }
});

Example: http://jsfiddle.net/petersendidit/YDZJs/1/

儭儭莪哋寶赑 2024-10-05 11:17:24

将垃圾桶也设为 .dropZone 怎么样?然后你会得到一个正确的 drop 事件,并且你可以正确处理删除。

让垃圾桶可分类可能会产生副作用,但我认为它们应该很容易解决。

如果这不能满足您的要求,您可以在某处上提供一个演示,以便我们知道我们到底需要做什么设法保持结构完整,同时仍然添加所需的功能?

How about making the trash can a .dropZone as well? Then you would get a proper drop event, and you could handle the deleting properly.

There may be side effects of making the trash can a sortable, but I figure they should be easy to work around.

If this doesn't meet your requirements, could you throw up a demo somewhere, so we know what exactly we'd have to work around to keep your structure intact, while still adding the functionality you need?

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