如何防止触发多个 jQuery UI droppables?

发布于 2024-08-01 23:37:53 字数 1206 浏览 9 评论 0原文

我有一个 jQuery UI 可拖动 和几个单独定义的 droppables。 由于其中一个 droppable 已配置为 tolerance: 'intersect',因此可以将一个可拖动对象同时放置到多种可放置对象上。

防止意外 droppable 触发的最佳方法是什么? 基本上,我想优先考虑 droppables,以便在触发另一个 droppables 时,具有 tolerance: 'intersect' 的 droppables 不会被触发。

更新 - 用于澄清问题的更多信息:

  • 所有 droppable 都配置了 tolerance: 'pointer',除了一类 droppable 的 tolerance: 'intersect '

  • 一类 droppable 具有 tolerance: 'intersect' 的原因是 droppable 非常窄,用户在使用 tolerance: 'pointer' 找到它们时遇到问题。

  • 将 droppable 移得更远不是一个选项。

  • 所有 droppable 均不重叠,但可拖动对象足够大,可以与具有 tolerance: 'intersect' 的 droppable 重叠,同时鼠标指针位于另一个具有 tolerance: 'pointer'< 的 droppable 上< /代码>。 通过这种方式,最多可以同时触发两个 droppable。

  • UI 的布局是为了在触发另一个 droppable 时忽略 tolerance: 'intersect' droppable 来确定用户的意图; 即,如果用户将鼠标指针移动到具有 tolerance: 'pointer' 的可放置对象上,则可以安全地假设他/她打算将其放置在那里。 问题是,我不知道如何忽略不需要的 droppable。

I have a jQuery UI draggable and several separately-defined droppables. Because one of the droppables is configured tolerance: 'intersect', it's possible for a draggable to be dropped on more than one kind of droppable at the same time.

What's the best way to prevent the unintended droppables from firing? Basically, I'd like to prioritize the droppables so that the droppables with tolerance: 'intersect' don't get triggered if another droppable was triggered.

Update - More info to clarify things:

  • All of the droppables are configured tolerance: 'pointer' except for one class of droppable with tolerance: 'intersect'.

  • The reason one class of droppable has tolerance: 'intersect' is that the droppables are really narrow, and users have problems finding them with tolerance: 'pointer'.

  • Moving the droppables further apart isn't an option.

  • None of the droppables overlap, but the draggable is large enough to overlap a droppable with tolerance: 'intersect' while the mouse pointer is over another droppable with tolerance: 'pointer'. At most two droppables can be triggered at once in this way.

  • The UI is laid out so the user's intentions can be determined by ignoring the tolerance: 'intersect' droppable if another droppable has been triggered; i.e. if the user moved the mouse pointer over a droppable with tolerance: 'pointer', it's safe to assume that he/she intended to drop it there. Problem is, I can't figure out how to ignore the unwanted droppable.

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

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

发布评论

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

评论(3

骷髅 2024-08-08 23:37:53

over: 中,为预期的 droppable 分配一个类,并从所有其他 droppable 中删除该类:

$(".dragArea").not($(this)).removeClass("dragHover");
$(this).addClass("dragHover");

然后在 drop: 中,检查该类是否已设置:

if(!$(this).is('.dragHover')){
    return false;
}

这样,仅触发了一个可掉落物。

In over:, assign a class to the intended droppable and remove the class from all other droppables:

$(".dragArea").not($(this)).removeClass("dragHover");
$(this).addClass("dragHover");

Then in drop:, check if the class is set:

if(!$(this).is('.dragHover')){
    return false;
}

This way, only one droppable is triggered.

过期情话 2024-08-08 23:37:53

也许在“不太喜欢”的可放置事件结束时,您可以检查可拖动是否也在“首选”可放置之上,以及是否禁用了“不太喜欢”的可放置。

抱歉使用术语,只是想集思广益。

Maybe in the over event of the "less preferred" droppable you could check if the draggable is also over the "preferred" droppable and if it is disable the "less preferred" droppable.

Sorry for the terminology, just trying to brainstorm.

Smile简单爱 2024-08-08 23:37:53

将它们彼此保持一定的物理距离,这样它们就不会同时掉落。 否则,你应该如何确定用户的意图? 您要计算每个相交可放置对象上可拖动对象的百分比吗?

Move them physically distant from one another so that they cannot be dropped on simultaneously. Otherwise, how are you supposed to determine what the user intended? Are you going to calculate percentages of the draggable on each intersecting droppable?

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