javascript - 如何区分拖放和拖放中止

标签 javascript html drag-and-drop

当 HTML5 拖动操作在另一个窗口结束时,Drop 事件会在目标窗口中触发,而 DragEnd 事件会在源窗口中的拖动元素上触发。

对于复制和移动,放置目标将使用 e.dataTransfer 携带的数据执行复制操作,对于移动操作,必须在源窗口中删除项目。

当事件在源窗口中触发时,DragEnd 处理程序应如何确定该操作是在放置中结束还是被中止?

仅仅知道是否正在进行复制或剪切操作是不够的;只有在目标成功时,剪切操作才会从源中删除该项目。如果您愿意,它是交易性的。

最佳答案

我找到了一个 answer in mdn .点击链接并向下滚动到完成拖动部分。不幸的是,此信息既不在 DragEnd 也不在 DataTransfer 文档页面中。

Once the drag is complete, a dragend event is fired at the source of the drag (the same element that received the dragstart event). This event will fire [whether] the drag was successful [or] cancelled. However, you can use the dropEffect property to determine what drop operation occurred.

If the dropEffect property has the value none during a dragend, then the drag was cancelled. Otherwise, the effect specifies which operation was performed. The source can use this information after a move operation to remove the dragged item from the old location.

句子结构和语法的强调和修复是我的。

Safari 8 完全崩溃了。它总是报告“无”作为放置事件中的放置效果。

关于javascript - 如何区分拖放和拖放中止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46952917/

相关文章:

javascript - 如何给特定值的<text>标签添加attr(id)-Js/Jquery

javascript - 将从 http API 返回的多个数据插入到 sql lite

上传图片时PHP表单处理错误

javascript - 文本 slider 在每次迭代后从左侧增加偏移量

python - 从 HTML 按钮运行 Python 脚本

Javascript : drag and drop image tag

javascript - 向下滚动页面后固定标题跳转

javascript - 需要对带有选项卡导航(分页)的猫头鹰幻灯片进行 jquery 和 litte html css 改进

java - Transferhandler 中的 getTransferData() 无法按预期多次删除 jtree 中的多个对象

javascript - 一次拖放多个项目作为堆栈