如何在 HTML5 DnD 中获取可拖动元素放置时的预览位置
我正在使用 HTML5 拖放功能做一个可视化编辑器,我需要将一个设置为可拖动的元素拖动到充当容器的 div 中。
某些浏览器提供了一种预览图像,它在我拖动元素时代表该元素,当我通过放置事件将元素放入容器中时,我需要获取用户想要放置他的位置。问题是我不知道浏览器提供的预览幽灵的位置,所以我不知道元素到底应该放置在哪里。
我使用了鼠标位置,但这不是我想要的,因为鼠标位置与预览的位置不同。有没有办法获取拖动元素预览的当前位置?
I'm doing a visual editor using HTML5 Drag and Drop and i need to drag an element set as draggable to a div who acts as a container.
Some browsers provides a kind of preview image that represents the element while i'm dragging it, and when i let the element in the container with the drop event, i need to get the position where the user wants to put him. The problem is that i don't know the position of the preview ghost provided by browsers, so i don't know where exactly the element should be positioned.
I used the mouse position but it's not what i wanted, because the mouse position is not ever the same as the preview's. Is there a way to get the current position of the preview of a dragging element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过使用 jQuery UI 来进行 DnD?我不确定您是否考虑过这一点,但如果您选择执行 jQuery UI 路线,这里有一些资源可能会对您有所帮助:
jQuery UI Draggable(另请参阅 Droppable)
jquery ui 拖/放从多个可拖动对象获取位置
Have you considered using jQuery UI to do your DnD? I'm not sure if you've considered that or not, but here are some resources that might help you in-case you do choose to do the jQuery UI route:
jQuery UI Draggable (also see Droppable)
jquery ui drag/drop getting position from multiple draggables