-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (26 loc) · 1020 Bytes
/
app.js
File metadata and controls
30 lines (26 loc) · 1020 Bytes
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
const menuToggle = document.querySelector(".toggle");
const showcase = document.querySelector(".showcase");
const current = document.querySelector("#current");
const imgs = document.querySelectorAll(".imgs img");
menuToggle.addEventListener("click", () => {
menuToggle.classList.toggle("active");
showcase.classList.toggle("active");
});
const opacity = 0.4;
// Set first image opacity
imgs[0].style.opacity = opacity;
// Using Es-6 Destructuring
//const [current,imgs]=[document.querySelector('#current'),document.querySelectorAll('.imgs img')]
imgs.forEach((img) => img.addEventListener("click", imgClick));
function imgClick(e) {
// Reset the opcaity
imgs.forEach((img) => (img.style.opacity = 1));
// change the current img to clicked image
current.src = e.target.src;
// Add fading class
current.classList.add("fade-in");
// Remove the Fade in class .5
setTimeout(() => current.classList.remove("fade-in"), 500);
// change the opacity to opacity var
e.target.style.opacity = opacity;
}