-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgallery.js
70 lines (60 loc) · 2.43 KB
/
gallery.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
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
69
70
document.addEventListener('DOMContentLoaded', function() {
const galleryContainer = document.querySelector('.gallery-container');
const lightbox = document.querySelector('.lightbox');
const lightboxImage = document.querySelector('.lightbox-image');
const lightboxVideo = document.querySelector('.lightbox-video');
const closeLightbox = document.querySelector('.close-lightbox');
// Handle gallery item clicks
galleryContainer.addEventListener('click', function(e) {
const galleryItem = e.target.closest('.gallery-item');
if (!galleryItem) return;
const video = galleryItem.querySelector('video');
const img = galleryItem.querySelector('img');
if (video) {
// Handle video
lightboxImage.style.display = 'none';
lightboxVideo.style.display = 'block';
lightboxVideo.src = video.querySelector('source').src;
lightboxVideo.play();
} else if (img) {
// Handle image
lightboxImage.style.display = 'block';
lightboxVideo.style.display = 'none';
lightboxImage.src = img.src;
}
lightbox.classList.add('active');
});
// Close lightbox
closeLightbox.addEventListener('click', function() {
lightbox.classList.remove('active');
lightboxVideo.pause();
lightboxVideo.currentTime = 0;
});
// Close lightbox when clicking outside
lightbox.addEventListener('click', function(e) {
if (e.target === lightbox) {
lightbox.classList.remove('active');
lightboxVideo.pause();
lightboxVideo.currentTime = 0;
}
});
});
// Filter functionality
const filterButtons = document.querySelectorAll('.filter-btn');
const galleryItems = document.querySelectorAll('.gallery-item');
filterButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
button.classList.add('active');
const filterValue = button.getAttribute('data-filter');
galleryItems.forEach(item => {
if (filterValue === 'all' || item.getAttribute('data-category') === filterValue) {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
});
});