-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
24 lines (22 loc) · 860 Bytes
/
script.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
let fileInput = document.getElementById("file-input");
let imageContainer = document.getElementById("images");
let numOfFiles = document.getElementById("num-of-files");
function preview(){
imageContainer.innerHTML = "";
numOfFiles.style.display = "";
numOfFiles.textContent = `${fileInput.files.length} Files Selected`;
for(i of fileInput.files){
let reader = new FileReader();
let figure = document.createElement("figure");
let figCap = document.createElement("figcaption");
figCap.innerText = i.name;
figure.appendChild(figCap);
reader.onload=()=>{
let img = document.createElement("img");
img.setAttribute("src",reader.result);
figure.insertBefore(img,figCap);
}
imageContainer.appendChild(figure);
reader.readAsDataURL(i);
}
}