-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlightbox.js
More file actions
32 lines (28 loc) · 1.04 KB
/
Copy pathlightbox.js
File metadata and controls
32 lines (28 loc) · 1.04 KB
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
(function() {
var lightbox = document.getElementById('lightbox');
var lightboxImg = document.getElementById('lightbox-img');
var lightboxClose = document.getElementById('lightbox-close');
if (!lightbox || !lightboxImg) return;
// Открытие по клику на .thumb
document.querySelectorAll('.project .thumb').forEach(function(thumb) {
thumb.addEventListener('click', function(e) {
var img = this.querySelector('img');
if (!img) return;
lightboxImg.src = img.src;
lightboxImg.alt = img.alt || 'Изображение проекта';
lightbox.classList.add('active');
document.body.style.overflow = 'hidden';
});
});
function closeLightbox() {
lightbox.classList.remove('active');
document.body.style.overflow = '';
}
lightboxClose.addEventListener('click', closeLightbox);
lightbox.addEventListener('click', function(e) {
if (e.target === this) closeLightbox();
});
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') closeLightbox();
});
})();