-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (57 loc) · 2.16 KB
/
index.js
File metadata and controls
68 lines (57 loc) · 2.16 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const menuBtn = document.querySelector('.menu-btn');
const navLinks = document.querySelector('.nav-links');
const navLinksList = document.querySelectorAll('.nav-links a');
if (menuBtn && navLinks) {
menuBtn.addEventListener('click', () => {
navLinks.classList.toggle('active');
menuBtn.classList.toggle('open');
menuBtn.setAttribute('aria-expanded', navLinks.classList.contains('active'));
});
navLinksList.forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
menuBtn.classList.remove('open');
menuBtn.setAttribute('aria-expanded', 'false');
});
});
}
const year = document.getElementById('year');
if (year) year.textContent = new Date().getFullYear();
const filterButtons = document.querySelectorAll('.filter-btn');
const galleryItems = document.querySelectorAll('.gallery-item');
filterButtons.forEach(button => {
button.addEventListener('click', () => {
const filter = button.dataset.filter;
filterButtons.forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
galleryItems.forEach(item => {
const show = filter === 'all' || item.dataset.category === filter;
item.classList.toggle('hide', !show);
});
});
});
const lightbox = document.querySelector('.lightbox');
const lightboxImg = document.querySelector('.lightbox img');
const lightboxClose = document.querySelector('.lightbox-close');
if (lightbox && lightboxImg && lightboxClose) {
galleryItems.forEach(item => {
item.addEventListener('click', () => {
lightboxImg.src = item.src;
lightboxImg.alt = item.alt;
lightbox.classList.add('show');
lightbox.setAttribute('aria-hidden', 'false');
});
});
const closeLightbox = () => {
lightbox.classList.remove('show');
lightbox.setAttribute('aria-hidden', 'true');
lightboxImg.src = '';
};
lightboxClose.addEventListener('click', closeLightbox);
lightbox.addEventListener('click', (event) => {
if (event.target === lightbox) closeLightbox();
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape' && lightbox.classList.contains('show')) closeLightbox();
});
}