forked from solygambas/html-css-javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
22 lines (20 loc) · 817 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
const modal = document.querySelector(".modal");
const previews = document.querySelectorAll(".gallery img");
const original = document.querySelector(".full-img");
const caption = document.querySelector(".caption");
previews.forEach((preview) => {
preview.addEventListener("click", () => {
modal.classList.add("open");
original.classList.add("open");
const originalSize = preview.getAttribute("data-original");
original.src = `https://source.unsplash.com/${originalSize}`;
caption.textContent = preview.alt;
// Reference: https://stackoverflow.com/questions/35213147/difference-between-textcontent-vs-innertext
});
});
modal.addEventListener("click", (e) => {
if (e.target.classList.contains("modal")) {
modal.classList.remove("open");
original.classList.remove("open");
}
});