如何防止触发多个 jQuery UI droppables?
我有一个 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 withtolerance: 'intersect'
.The reason one class of droppable has
tolerance: 'intersect'
is that the droppables are really narrow, and users have problems finding them withtolerance: '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 withtolerance: '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 withtolerance: '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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
over:
中,为预期的 droppable 分配一个类,并从所有其他 droppable 中删除该类:然后在
drop:
中,检查该类是否已设置:这样,仅触发了一个可掉落物。
In
over:
, assign a class to the intended droppable and remove the class from all other droppables:Then in
drop:
, check if the class is set:This way, only one droppable is triggered.
也许在“不太喜欢”的可放置事件结束时,您可以检查可拖动是否也在“首选”可放置之上,以及是否禁用了“不太喜欢”的可放置。
抱歉使用术语,只是想集思广益。
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.
将它们彼此保持一定的物理距离,这样它们就不会同时掉落。 否则,你应该如何确定用户的意图? 您要计算每个相交可放置对象上可拖动对象的百分比吗?
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?