how to disable dragend animation in html5

筅森魡賤 提交于 2020-01-13 10:08:11

问题


html is

<div id="test" draggable='true'></div>

and I can drag this div,but when I drop the element, there is a animation that element back to it's origin position

how to disable this animate? I use preventDefault() in dragend event, it not working?

My English is not vert good ,thank you very much

enter image description here


回答1:


In order to prevent the animation, you need the drop event to fire. For the drop event to fire, you need to call preventDefault() in the handler for dragover.

document.addEventListener('dragover', function(e) { e.preventDefault() })

Example in MDN docs shows the same thing: https://developer.mozilla.org/en-US/docs/Web/Events/drop#Example

An old blog post describing the quirks of HTML5 Drag and Drop API: https://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html



来源:https://stackoverflow.com/questions/42991709/how-to-disable-dragend-animation-in-html5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!