forked from lavishmeena2764/GAM24
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptactivity.js
More file actions
91 lines (79 loc) · 3.19 KB
/
scriptactivity.js
File metadata and controls
91 lines (79 loc) · 3.19 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
document.addEventListener('DOMContentLoaded', function() {
const galleryItems = document.querySelectorAll('.gallery-img');
const lightbox = document.getElementById('lightbox');
const lightboxContent = document.querySelector('.carousel-container');
const prevBtn = document.querySelector('.prev-btn');
const nextBtn = document.querySelector('.next-btn');
const closeBtn = document.querySelector('.close-btn');
let currentPhotos = []; // Array to hold current photos being displayed
let currentIndex = 0;
// Define photo sets for each activity
const photoSets = {
"Activity 1": [
'images/gallery-img5.jpg',
'images/gallery-img6.jpg',
'images/gallery-img7.jpg'
],
"Activity 2": [
'images/activity2_photo1.jpg',
'images/activity2_photo2.jpg',
'images/activity2_photo3.jpg'
],
// Add more activities and their respective photo sets as needed
};
// Function to update lightbox content with current activity photos
function updateLightbox(activityTitle) {
currentPhotos = photoSets[activityTitle];
currentIndex = 0; // Reset index to start at the first image
// Clear previous content
lightboxContent.innerHTML = '';
// Create image element for the current photo
const img = document.createElement('img');
img.src = currentPhotos[currentIndex];
img.classList.add('lightbox-img'); // Add a class to style the images
lightboxContent.appendChild(img);
}
// Event listeners for gallery items
galleryItems.forEach(function(item) {
item.addEventListener('click', function(e) {
e.preventDefault();
const activityTitle = item.getAttribute('data-title');
// Update lightbox content for the clicked activity
updateLightbox(activityTitle);
// Show lightbox
lightbox.style.display = 'flex';
});
});
// Previous button event
prevBtn.addEventListener('click', function() {
if (currentIndex > 0) {
currentIndex--;
const img = document.createElement('img');
img.src = currentPhotos[currentIndex];
img.classList.add('lightbox-img'); // Add a class to style the images
lightboxContent.innerHTML = '';
lightboxContent.appendChild(img);
}
});
// Next button event
nextBtn.addEventListener('click', function() {
if (currentIndex < currentPhotos.length - 1) {
currentIndex++;
const img = document.createElement('img');
img.src = currentPhotos[currentIndex];
img.classList.add('lightbox-img'); // Add a class to style the images
lightboxContent.innerHTML = '';
lightboxContent.appendChild(img);
}
});
// Close lightbox on close button click
closeBtn.addEventListener('click', function() {
lightbox.style.display = 'none';
});
// Close lightbox on outside click
lightbox.addEventListener('click', function(e) {
if (e.target === lightbox) {
lightbox.style.display = 'none';
}
});
});