Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

on drop, drag, dragover event

<!DOCTYPE html>
<html lang=en>
<title>Examples of using the ondrag Global Event Attribute</title>
<meta content="width=device-width">
<style>
  div {
    margin: 0em;
    padding: 2em;
  }
  #source {
    color: blue;
    border: 1px solid black;
  }
  #target {
    border: 1px solid black;
  }
</style>
</head>
<script>
function drag_handler(ev) {
 console.log("Drag");
}

function dragstart_handler(ev) {
 console.log("dragStart");
 ev.dataTransfer.setData("text", ev.target.id);
}

function drop_handler(ev) {
 console.log("Drop");
 ev.currentTarget.style.background = "lightyellow";

 ev.preventDefault();
 var data = ev.dataTransfer.getData("text");
 ev.target.appendChild(document.getElementById(data));
}

function dragover_handler(ev) {
 console.log("dragOver");
 ev.preventDefault();
}
</script>
<body>
<h1>Examples of <code>ondrag</code>, <code>ondrop</code>, <code>ondragstart</code>, <code>ondragover</code></h1>
 <div class="source">
   <p id="source" ondrag="drag_handler(event);" ondragstart="dragstart_handler(event);" draggable="true">
     Select this element, drag it to the Drop Zone and then release the selection to move the element.</p>
 </div>
 <div id="target" ondrop="drop_handler(event);" ondragover="dragover_handler(event);">Drop Zone</div>
</body>
</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: moment js date between two dates 
Javascript :: convert json to 2d array 
Javascript :: javascript regex not in a set of characters 
Javascript :: box shadow generador react native 
Javascript :: mui link icon 
Javascript :: how to add key value pair in object 
Javascript :: javascript parseInt() method 
Javascript :: s3.getobject nodejs example 
Javascript :: npm modal 
Javascript :: leaflet cdn 
Javascript :: javascript split method 
Javascript :: Jest DOM Manipulation 
Javascript :: filter buttons react 
Javascript :: Each then() should return a value or throw 
Javascript :: eslint disable line 
Javascript :: is value in list javascript 
Javascript :: process.env type 
Javascript :: js animations 
Javascript :: parallax using npm parallax 
Javascript :: javascript sorting an array 
Javascript :: jquery properly work 
Javascript :: GET FORM VALUE 
Javascript :: make forn awesome icon clickable in react 
Javascript :: React native pdf creater html-to-pdf 
Javascript :: js include another 
Javascript :: Vowel Count 
Javascript :: react native geocoding 
Javascript :: splice and slice in javascript 
Javascript :: react native measure 
Javascript :: events in javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =