JQuery 可拖动 - 无重叠
是否可以说“可拖动的 div -> 没有重叠”?
我认为主要问题是位置:绝对; ... 正确的?
亲切的问候 彼得
is it possible to say "draggable div's -> no overlap" ?
I think the mainproblem is the position:absolute; ... right?
kind reagards
Peter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试 jquery-collision 加上 jquery-ui-draggable-collision。全面披露:我刚刚在 sourceforge 上编写并发布了这些内容。
第一个允许这样做:
这是与“#collider”重叠的所有“.obstacle”的列表。
第二个允许:
它为您提供(除其他外)一个要绑定的“碰撞”事件:
您甚至可以设置:
以防止“#collider”在拖动时与任何“.obstacle”重叠。
You can try jquery-collision plus jquery-ui-draggable-collision. Full disclosure: I just wrote and released these on sourceforge.
The first allows this:
which is the list of all ".obstacle" that overlap "#collider".
The second allows:
Which gives you (among other things), a "collision" event to bind to:
And you can even set:
to prevent "#collider" from ever overlapping any ".obstacle" while dragging.
jQuery UI Draggable 中没有用于碰撞检测的内置函数,除非您实际上在排序之类的事情之后。与您想要的最接近的内置内容是 sortable 的 plceholder,看起来像这样。
简而言之,每个拖动元素的碰撞检测在性能方面并不是微不足道的(取决于元素的数量),因此它被排除在库之外,因为这是一个非常罕见的请求。但是,您可以在 draggable 的
drag
事件内自行计算碰撞 如果您确实需要碰撞检测。There isn't a built-in function for collision detection in jQuery UI draggable, unless you're actually after something like sorting. The closest thing that's built-in to what you want is sortable's plceholder, which looks like this.
The short version is collision detection with every dragged element isn't trivial in terms of performance (depending on the number of elements), so it's left out of the library since it's a very rare request. You could however calculate the collisions yourself inside the draggable's
drag
event if you really do need the collision detection.