-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
31 lines (22 loc) · 912 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
// const current = document.querySelector('#current');
// const imgs = document.querySelectorAll('.imgs img')
// imgs.forEach(img => img.addEventListener('click', e => (current.src = e.target.src)));
const current = document.querySelector('#current');
const imgs = document.querySelector('.imgs');
const img = document.querySelectorAll('.imgs img');
const opacity = 0.6;
// Set first img opacity
img[0].style.opacity = opacity;
imgs.addEventListener('click', imgClick);
function imgClick(e) {
// Reset the opacity
img.forEach(img => (img.style.opacity = 1));
// Change current image to src of clicked image
current.src = e.target.src;
// Add fade in class
current.classList.add('fade-in');
// Remove fade-in class after .5 seconds
setTimeout(() => current.classList.remove('fade-in'), 500);
// Change the opacity to opacity var
e.target.style.opacity = opacity;
}