当 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/