Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable dragend animation in html5

Tags:

html

drag

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

like image 822
user1861806 Avatar asked Mar 24 '17 04:03

user1861806


People also ask

How to make element draggable in HTML5?

To make an object draggable set draggable=true on that element. Just about anything can be drag-enabled: images, files, links, files, or any markup on your page. Our example creates an interface to rearrange columns that have been laid out with CSS Grid.

What is Dragend?

The dragend event is fired when a drag operation is being ended (by releasing a mouse button or hitting the escape key).

Can I use HTML drag and drop API?

HTML Drag and Drop interfaces enable applications to use drag-and-drop features in browsers. The user may select draggable elements with a mouse, drag those elements to a droppable element, and drop them by releasing the mouse button.


1 Answers

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

like image 84
freefood89 Avatar answered Oct 05 '22 12:10

freefood89