Created
May 12, 2014 07:25
-
-
Save carlosrojaso/902d31e2a8e4caa474c0 to your computer and use it in GitHub Desktop.
drag and drop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<style> | |
#div1 {width:350px;height:70px;padding:10px;border:1px solid #aaaaaa;} | |
</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> | |
<br> | |
<img id="drag1" src="http://carlosrojasblog.com/wp-content/uploads/2013/09/logotipo_w4.png" draggable="true" ondragstart="drag(event)" width="336" height="69"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment