Last active
August 29, 2015 14:03
-
-
Save smallnewer/bf0e3d919488a82c3412 to your computer and use it in GitHub Desktop.
拖拽读取文件。之前写的,摘出来做备份
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
var dropbox = $$("#canvas")[0]; | |
dropbox.ondragenter = function (e) { | |
e.preventDefault(); | |
dropbox.innerHTML = "松开鼠标"; | |
} | |
dropbox.ondragleave = function (e) { | |
e.preventDefault(); | |
dropbox.innerHTML = "图片拖放至此"; | |
} | |
dropbox.ondragover = function (e) { | |
e.preventDefault(); | |
} | |
dropbox.ondrop = function (e) { | |
e.preventDefault(); | |
init(e.dataTransfer.files) | |
} | |
function init (files) { | |
if (files.length ==0 || files[0].type.indexOf("image") == -1) { | |
return | |
}; | |
var fr = new FileReader(); | |
var t = fr.readAsDataURL(files[0]) | |
fr.onload = function (e) { | |
var img = new Image(); | |
img.src = fr.result; | |
img.onload = function () { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment