使用 HTML5 可以使元素“不可见”。用于拖/放交互?
仍在尝试 将拖放和移动元素与鼠标结合起来 当我'时,我正在努力解决 dragenter
和 dragleave
父元素不被调用的问题米移动子元素。这看起来很自然,因为该元素始终悬停在父元素上并防止为父元素调用 dragenter
。
我尝试在 dragenter
、dragleave
、dragover
中调用 stopPropagation()
和 preventDefault()
子元素的 code>、dragstart
和 drag
事件,但没有实际效果。
另一个问题似乎解决类似的问题,但如果我正确理解的话,没有真正的解决方案。
也许兔子洞里太黑了,看不到明显的东西 - 如何防止拖动的项目避免调用其父级 dragenter
/dragleave
事件?
在另一个层面上,我只想知道该元素是否已被删除到父元素之外(然后将其返回到原始位置)。有更简单的方法吗?
这是我当前的代码 - 在当前状态下,元素正在用鼠标移动,从而防止dragenter
或 dragleave
被调用。
停用 draggable_element
的实际移动将使 dragenter 和
dragleave
在离开父/目标区域时以及在输入拖动的元素时被调用(我以某种方式无法避免)。
Still trying to combine drag&drop and moving an element with the mouse I'm struggling with dragenter
and dragleave
not being called for a parent element when I'm moving the child element. This seems quite natural because the element always hovers over the parent element and prevents dragenter
being called for the parent.
I tried to call stopPropagation()
and preventDefault()
in dragenter
, dragleave
, dragover
, dragstart
and drag
events for the child element but with no real effect.
Another question seems to address a similar issue but with no real solution if I get this correctly.
Maybe it's just too dark down here in the rabbit hole to see the obvious - how do I prevent the dragged item from avoiding its parents dragenter
/dragleave
events to be called?
On another level I just want to know if the element has been dropped outside the parent element (to then return it to it's original position). Is there an easier approach?
Here is my current code - In the current state the element is being moved with the mouse and thus preventing dragenter
or dragleave
being called.
Deactivating the actual movement of draggable_element
will make dragenter
and dragleave
be called when leaving the parent/target area but also when the dragged element is being entered (what I somehow can't avoid).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了它 - 而不是摆弄拖/放事件,您只需为拖动的项目停用
pointer-events
,以避免不需要的dragenter
/dragleave
父级的事件,然后再次将其重新打开(默认情况下必须激活它才能首先启用拖动)。这是一个工作示例: https://jsfiddle.net/03a9s4ur/10/
Found it - instead fiddling with the drag/drop events you just have to deactivate
pointer-events
for the dragged item to avoid unwanteddragenter
/dragleave
events for the parent and turn it back on again afterwards (it has to be activated by default to enable dragging in the first place).Here is a working example: https://jsfiddle.net/03a9s4ur/10/