Last active
December 14, 2015 02:59
-
-
Save danimal141/5018139 to your computer and use it in GitHub Desktop.
drop file sample
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>File API Sample</title> | |
<style type="text/css"> | |
.droppable { | |
width: 200px; | |
height: 200px; | |
border:1px solid red; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="drop" class="droppable">ここに画像をドロップ!</div> | |
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<script> | |
$("#drop").on("dragover",function(event){ | |
var type = event.originalEvent.dataTransfer.types[0]; | |
if(type== "Files"){ | |
event.preventDefault(); | |
} | |
}); | |
$("#drop").on("drop",function(event){ | |
event.preventDefault(); | |
var file = event.originalEvent.dataTransfer.files[0]; | |
var reader = new FileReader(); | |
reader.onload = function(e){ | |
$("#drop").empty().css({ | |
"border":"none", | |
"width" :"100%", | |
"height" :"100%" | |
}).append($("<img>").attr("src",e.target.result)); | |
}; | |
reader.readAsDataURL(file); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment