-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
33 lines (27 loc) · 999 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
23
24
25
26
27
28
29
30
31
32
33
document.addEventListener("DOMContentLoaded", () => {
// ===> DOM elements <=== //
const $imagesContainer = document.getElementById('images-container');
const $lightbox = document.getElementById('lightbox');
// ===> Event listeners and triggers <=== //
// Show lightbox
$imagesContainer.addEventListener('click', e => {
const imageWrapper = e.target.closest('.image-wrapper');
if (imageWrapper) {
const image = imageWrapper.querySelector('img');
if (image) {
$lightbox.innerHTML = '<div class="close-lightbox"></div>' + image.outerHTML;
$lightbox.classList.add('show');
}
}
});
// Hide Lightbox
$lightbox.addEventListener('click', (e) => {
if (!e.target.hasAttribute('src')) {
$lightbox.classList.remove('show');
}
});
// Loading...
setTimeout(() =>
$imagesContainer.classList.remove('loading')
, 1500);
});