-
Notifications
You must be signed in to change notification settings - Fork 2
/
showImg.js
31 lines (26 loc) · 1.05 KB
/
showImg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function handleFileSelect(evt) {
// remove previous image, if present
document.getElementById('list').innerHTML = '';
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render image.
var span = document.createElement('span');
span.innerHTML = ['<img id="pic" class=\"thumb\" src=\"', e.target.result,
'\" height="700px"/>'].join('');
document.getElementById('list').insertBefore(span, null);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
document.getElementById('img').addEventListener('change', handleFileSelect, false);