Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Drag & Drop Change icon/cursor while dragging

I'm wondering how to change during dragging (dragover/dragenter) icon/cursor when I dragenter for example to deny or allow section. Of course, I can move with cursor a part of DOM positioned absolutely, but I'm interested in native HTML5 solution.

Thanks!

like image 856
Alex Ivasyuv Avatar asked Apr 12 '12 07:04

Alex Ivasyuv


People also ask

How do I drag data in HTML5?

Drag and Drop Process If you want to drag an element, you need to set the draggable attribute to true for that element. Set an event listener for dragstart that stores the data being dragged. The event listener dragstart will set the allowed effects (copy, move, link, or some combination).

What is drag in HTML?

HTML Drag and Drop (DnD) is a feature of HTML5. It is a powerful user interface concept which is used to copy, reorder and delete items with the help of mouse. You can hold the mouse button down over an element and drag it to another location. If you want to drop the element there, just release the mouse button.

How do I drag and drop an image in HTML5?

Firstly, you need to mark the element (image in this case) as draggable which you want to drag. Now, you need to specify three attributes that will call the respective events or functions – ondragstart, ondragover, and ondrop. Finally, calling the respective JavaScript function will do the job.


1 Answers

You are after dropEffect:

Initialize it in dragstart:

event.dataTransfer.effectAllowed = "copyMove"; 

Update it in dragenter:

event.dataTransfer.dropEffect = "copy"; 
like image 133
zupa Avatar answered Sep 22 '22 02:09

zupa