Skip to content

Instantly share code, notes, and snippets.

@rodmanwu
Created January 4, 2013 06:37
Show Gist options
  • Save rodmanwu/4450436 to your computer and use it in GitHub Desktop.
Save rodmanwu/4450436 to your computer and use it in GitHub Desktop.
HTML: Darg and drop
<!doctype html>
<html>
<head>
<style type="text/css">
#div1 {width: 350px;height: 200px;padding: 10px;border: 2px solid #FFFFFF;}
</style>
<script >
function allowDrop(ev)
{
ev.preventDefault();
}
function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}
function drop(ev)
{
ev.preventDefault();
var data = ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>
<p> Drag the W3Schools image into the rectangle:</p>
<div id = "div1" ondrop="drop(event)"
ondragover="allowDrop(event)"></div>
<img id="drag1" src="img_w3slogo.gif" draggable = "true" ondragstart = "drag(event)"
width = "88" height = "31">
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment