Last active
August 29, 2015 14:22
-
-
Save agounaris/c165df5c98411c4d3c1c to your computer and use it in GitHub Desktop.
Grab drop events with jquery
This file contains 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> | |
<meta charset="utf-8"> | |
<title>JS Drop Events</title> | |
<style media="screen"> | |
.dropzone{ | |
width:300px; | |
height:100px; | |
line-height:100px; | |
border:2px dashed #CCC; | |
text-align:center; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="dropzone">Drop here</div> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
var dropZone = $('.dropzone'); | |
dropZone.on('dragover', function(e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
}); | |
dropZone.on('dragenter', function(e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
}); | |
dropZone.on('drop', function(e){ | |
if(e.originalEvent.dataTransfer){ | |
if(e.originalEvent.dataTransfer.files.length) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
var files = e.originalEvent.dataTransfer.files; | |
console.log('Do something with the files'); | |
console.log(files); | |
} | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment