-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
73 lines (57 loc) · 1.7 KB
/
app.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
66
67
68
69
70
const images = [
{
previewUrl: "./images/github.png",
thumbnailUrl: "./images/github.png"
},
{
previewUrl: "./images/google.png",
thumbnailUrl: "./images/google.png"
},
{
previewUrl: "./images/linkedin.png",
thumbnailUrl: "./images/linkedin.png"
},
{
previewUrl: "./images/pinterest.png",
thumbnailUrl: "./images/pinterest.png"
},
{
previewUrl: "./images/twitter.png",
thumbnailUrl: "./images/twitter.png"
}
];
console.log(images);
const preview = document.querySelector("#preview");
const thumbs = document.querySelector("#thumbs");
// create thumbnails
function createImages() {
// create ul element
const ul = document.createElement("ul");
for (let i = 0; i < images.length; i++ ) {
// create image element
const img = document.createElement("img");
const li = document.createElement("li");
img.src = images[i].thumbnailUrl;
img.classList.add('thumbnailUrl');
li.appendChild(img);
ul.appendChild(li);
thumbs.appendChild(ul);
img.addEventListener('click', previewImages);
}
}
console.log(createImages());
// preview image
function previewImages(event) {
console.log(event.target.getAttribute("src"));
console.log(images[0].thumbnailUrl);
const img = document.createElement("img");
for (let i = 0; i < images.length; i++ ) {
if(event.target.getAttribute("src") === images[i].thumbnailUrl) {
img.setAttribute("width", "350");
img.setAttribute("height", "350");
img.src = images[i].previewUrl;
preview.innerHTML = "";
preview.appendChild(img);
}
}
}