Java Techies - Solution for All
Java Techies - Solution for All
Drag and Drop concept is very useful to create a graphical user interface.
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)" > <img src="htm.png" draggable="true" ondragstart="drag(event)" id="drag1" width="88" height="31"></div> <div id="div2" align="center"ondrop="drop(event)" ondragover="allowDrop(event)"></div>
| Events | Description |
|---|---|
dragstart | Start when the user start dragging the item. |
dragenter | Execute when the mouse is first moved over the target element while a drag is occuring. |
dragover | This event is execute as the mouse is moved over an element when a drag is occuring. |
dragleave | This event is execute when the mouse leaves an element while a drag is occuring. |
drag | Executes every time the mouse is moved while the object is being dragged. |
drop | The drop event is execute on the element where the drop was occured at the end of the drag operation. |
dragend | Executes when the user releases the mouse button while dragging an object. |
The event listener methods for all the drag and drop events accept Event object which has a readonly attribute called dataTransfer.
function EnterHandler(event) {
DataTransfer dt = event.dataTransfer;
.............
}
The DataTransfer object holds data about the drag and drop operation.| S.N. | DataTransfer attrobutes | Description |
|---|---|---|
| 1 | dataTransfer.dropEffect [ = value ] | Returns the kind of operation that is currently selected. This attribute can be set, to change the selected operation. The possible values are none, copy, link, and move. |
| 2 | dataTransfer.effectAllowed [ = value ] |
Returns the kinds of operations that are to be allowed. This attribute can be set, to change the allowed operations. The possible values are none, copy, copyLink, copyMove, link, linkMove, move, all and uninitialized. |
| 3 | dataTransfer.types | Returns a DOMStringList listing the formats that were set in the dragstart event. In addition, if any files are being dragged, then one of the types will be the string "Files". |
| 4 | dataTransfer.clearData( [ format ] ) |
Removes the data of the specified formats. Removes all data if the argument is omitted. |
| 5 | dataTransfer.setData(format, data) |
Adds the specified data. |
| 6 | data = dataTransfer.getData(format) |
Returns the specified data. If there is no such data, returns the empty string. |
| 7 | dataTransfer.files |
Returns a FileList of the files being dragged, if any. |
| 8 | dataTransfer.setDragImage(element, x, y) |
Uses the given element to update the drag feedback, replacing any previously specified feedback. |
| 9 | dataTransfer.addElement(element) |
Adds the given element to the list of elements used to render the drag feedback. |
Step 1: Making an Object DraggableStep 2: Dropping the ObjectExplore the world of open-source software with Groovy Grails!
— Har Narayan (@har_narayan44) December 6, 2025
Check out their collection of amazing open-source projects and get inspired to contribute or start your own project!
Visit: https://t.co/LYNd8Cs3N7
#OpenSource #GroovyGrails #SoftwareDevelopment #Innovation"


