Skip to content

Instantly share code, notes, and snippets.

@agounaris
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agounaris/c165df5c98411c4d3c1c to your computer and use it in GitHub Desktop.
Save agounaris/c165df5c98411c4d3c1c to your computer and use it in GitHub Desktop.
Grab drop events with jquery
<!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