-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
65 lines (54 loc) · 1.84 KB
/
main.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// get input type file
let file = document.getElementById("myfile");
let columns = document.querySelectorAll(".column");
// create array to store image tag
let arrImg = [];
// event handler for input type file
file.onchange = () => {
// get files from the selected folder
for (const key in file.files) {
const element = file.files[key];
if (element.type === "image/jpg" || element.type === "image/png"|| element.type === "image/jpeg") {
// call minParent() function and obtain div which has minimun child nodes
let parent_column = minParent(columns);
// call createImg() Function and append images one by one in the column div
let img = createImg(element.webkitRelativePath);
// store images in the array for animation
arrImg[key] = img;
// append images in the parent node
parent_column.appendChild(img);
}
}
// create variable for index number
let i = 0;
let clearinter = setInterval(() => {
arrImg[i].setAttribute("style", "display : initial");
arrImg[i].classList.add("animated", "zoomIn");
i++;
// clear set interval when i is equal to array lenght
i == arrImg.length ? clearInterval(clearinter) : undefined;
}, 200);
};
// obtain parent node which has minimun child
function minParent(parentNode) {
let arr = [];
// get the children of the parent nodes
parentNode.forEach((element, i) => {
arr[i] = element.children.length;
});
// get min number from array
let min = Math.min.apply(null, arr);
// get parent which has min child nodes.
for (let i = 0; i < parentNode.length; i++) {
if (parentNode[i].children.length == min) {
return parentNode[i];
}
}
}
// create images with source attribute
function createImg(imgsrc) {
let img = document.createElement("img");
img.setAttribute("src", imgsrc);
img.className = "img";
return img;
}