-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
42 lines (35 loc) · 1004 Bytes
/
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
var photoNumber;
item = document.querySelector(".items");
button = document.querySelector(".btn");
document.addEventListener("DOMContentLoaded", () => {
getPic();
});
function preview() {
const apiUrl = "https://picsum.photos/id/" + photoNumber + "/400/200";
const gallery = document.createElement("figure");
gallery.id = +photoNumber + 1;
let id = gallery.id;
gallery.innerHTML = `<img src=${apiUrl} loading="lazy" decoding="async">
<figcaption>Picture ${photoNumber + 1} </figcaption>
`;
const close = document.createElement("i");
close.className = "material-icons";
close.addEventListener("click", () => {
removePhoto(id);
});
close.innerHTML = "✕";
gallery.appendChild(close);
item.appendChild(gallery);
}
function getPic() {
for (photoNumber = 0; photoNumber < 10; photoNumber++) {
preview();
}
}
function addPhoto() {
preview();
photoNumber = photoNumber + 1;
}
function removePhoto(id) {
document.getElementById(id).remove();
}