简体   繁体   English

禁用拖放 Chrome/Safari 的动画

[英]Disable animation for drag and drop Chrome/Safari

http://www.html5rocks.com/en/tutorials/dnd/basics/ http://www.html5rocks.com/en/tutorials/dnd/basics/

In the example here (scroll to the bottom and try the last example), when you drag out the element and don't drop it anywhere, it is positioned back to its default place and there is an animation for positioning to its default place (Chrome/Safari).在此处的示例中(滚动到底部并尝试最后一个示例),当您拖出元素并且不要将其放在任何地方时,它会被定位回其默认位置,并且有一个用于定位到其默认位置的动画(铬/Safari)。 I would like to disable that animation.我想禁用该动画。

Is there some sort of special property for webkit, that will allow me to do this? webkit 是否有某种特殊属性,可以让我这样做?

Found answer here and it works in my case https://stackoverflow.com/a/51697038/1770586在这里找到答案,它适用于我的情况https://stackoverflow.com/a/51697038/1770586

In order to prevent the animation, you need the drop event to fire.为了防止动画,您需要触发 drop 事件。 For the drop event to fire, you need to call preventDefault() in the handler for dragover.要触发放置事件,您需要在处理程序中调用 preventDefault() 以进行拖动。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM