Skip to content

Commit 9208a86

Browse files
committed
added more images and scrollable thumbnail
1 parent dad9929 commit 9208a86

File tree

4 files changed

+171
-24
lines changed

4 files changed

+171
-24
lines changed

_pages/gallery.md

Lines changed: 131 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,114 @@ title: Gallery
66
nav: true
77
nav_order: 8
88
---
9+
10+
911
<div class="carousel" style="text-align: center;">
10-
<div style="position: relative; display: inline-block; width: 80%;">
11-
<div class="carousel-slide">
12-
<img class="carousel-image" src="/assets/img/lab_photo.jpg" alt="Lab Photo">
13-
<div class="caption">KGML Team</div>
14-
</div>
15-
16-
<div class="carousel-slide" style="display:none;">
17-
<img class="carousel-image" src="/assets/img/jie_grad_celebration.jpg" alt="Graduation Celebration">
18-
<div class="caption">Jie’s PhD Defense Celebration</div>
19-
</div>
20-
12+
<div style="position: relative; display: inline-block; width: 80%;" id="carousel-container">
2113
<button class="prev" onclick="changeSlide(-1)">&#10094;</button>
2214
<button class="next" onclick="changeSlide(1)">&#10095;</button>
2315
</div>
16+
17+
<!-- Scrollable Thumbnail strip (centered) -->
18+
<div id="thumbnail-container-wrapper" style="display: flex; justify-content: center; margin-top: 20px;">
19+
<div id="thumbnail-container" style="display: inline-block; width: 80%; overflow-x: auto; white-space: nowrap; padding: 10px 0;">
20+
</div>
21+
</div>
2422
</div>
2523

2624
<script>
2725
let slideIndex = 0;
28-
showSlides(slideIndex);
26+
let slides = [];
27+
let autoSlideInterval;
28+
29+
// Function to load the JSON data
30+
async function loadGallery() {
31+
try {
32+
const response = await fetch('/assets/img/gallery/gallery.json?v=' + new Date().getTime());
33+
const images = await response.json();
34+
createCarousel(images);
35+
} catch (error) {
36+
console.error("Error loading gallery JSON:", error);
37+
}
38+
}
2939

40+
// Function to dynamically generate carousel slides and thumbnails
41+
function createCarousel(images) {
42+
const carouselContainer = document.getElementById('carousel-container');
43+
const thumbnailContainer = document.getElementById('thumbnail-container');
44+
45+
images.forEach((image, index) => {
46+
// Create the slide
47+
const slideDiv = document.createElement('div');
48+
slideDiv.classList.add('carousel-slide');
49+
if (index !== 0) slideDiv.style.display = "none"; // Only show the first image
50+
slides.push(slideDiv); // Store slides in array
51+
52+
const img = document.createElement('img');
53+
img.classList.add('carousel-image');
54+
img.src = image.src;
55+
img.alt = image.caption;
56+
img.style.width = "100%";
57+
58+
const caption = document.createElement('div');
59+
caption.classList.add('caption');
60+
caption.textContent = image.caption;
61+
62+
slideDiv.appendChild(img);
63+
slideDiv.appendChild(caption);
64+
carouselContainer.insertBefore(slideDiv, carouselContainer.children[0]); // Add slides before buttons
65+
66+
// Create the thumbnail
67+
const thumbnail = document.createElement('img');
68+
thumbnail.src = image.src;
69+
thumbnail.alt = image.caption;
70+
thumbnail.classList.add('thumbnail');
71+
thumbnail.onclick = () => {
72+
showSlide(index); // Go to specific slide on click
73+
clearInterval(autoSlideInterval); // Stop auto sliding when clicked
74+
startAutoSlide(); // Restart auto sliding
75+
};
76+
thumbnailContainer.appendChild(thumbnail);
77+
});
78+
79+
// Initialize first thumbnail as active
80+
updateActiveThumbnail(slideIndex);
81+
startAutoSlide(); // Start auto-sliding after creating the carousel
82+
}
83+
84+
// Function to change slides (next/previous)
3085
function changeSlide(n) {
31-
showSlides(slideIndex += n);
86+
slideIndex += n;
87+
if (slideIndex >= slides.length) { slideIndex = 0 }
88+
if (slideIndex < 0) { slideIndex = slides.length - 1 }
89+
showSlide(slideIndex);
3290
}
3391

34-
function showSlides(n) {
35-
let i;
36-
let slides = document.getElementsByClassName("carousel-slide");
37-
if (n >= slides.length) { slideIndex = 0 }
38-
if (n < 0) { slideIndex = slides.length - 1 }
39-
for (i = 0; i < slides.length; i++) {
40-
slides[i].style.display = "none";
41-
}
42-
slides[slideIndex].style.display = "block";
92+
// Function to show a specific slide and update active thumbnail
93+
function showSlide(n) {
94+
slides.forEach(slide => slide.style.display = "none"); // Hide all slides
95+
slides[n].style.display = "block"; // Show the selected slide
96+
slideIndex = n;
97+
updateActiveThumbnail(n); // Update thumbnail highlight
4398
}
99+
100+
// Function to update the active thumbnail
101+
function updateActiveThumbnail(index) {
102+
const thumbnails = document.querySelectorAll('.thumbnail');
103+
thumbnails.forEach(thumb => thumb.classList.remove('active')); // Remove active class from all
104+
thumbnails[index].classList.add('active'); // Add active class to current thumbnail
105+
}
106+
107+
// Function to start auto-sliding every 3 seconds
108+
function startAutoSlide() {
109+
autoSlideInterval = setInterval(() => {
110+
slideIndex = (slideIndex + 1) % slides.length; // Automatically move to the next slide
111+
showSlide(slideIndex);
112+
}, 3000); // 3000ms = 3 seconds
113+
}
114+
115+
// Load the gallery when the page loads
116+
loadGallery();
44117
</script>
45118

46119
<style>
@@ -70,11 +143,11 @@ nav_order: 8
70143
}
71144

72145
.prev {
73-
left: 10px; /* Adjusted to position the arrow inside the 90% container */
146+
left: 10px;
74147
}
75148

76149
.next {
77-
right: 10px; /* Adjusted to position the arrow inside the 90% container */
150+
right: 10px;
78151
}
79152

80153
.caption {
@@ -88,4 +161,38 @@ nav_order: 8
88161
.carousel-slide {
89162
position: relative;
90163
}
164+
165+
/* Thumbnails */
166+
.thumbnail {
167+
width: 80px;
168+
height: auto;
169+
margin: 0 5px;
170+
cursor: pointer;
171+
opacity: 0.6;
172+
transition: opacity 0.3s ease;
173+
display: inline-block;
174+
}
175+
176+
.thumbnail:hover {
177+
opacity: 1;
178+
}
179+
180+
.thumbnail.active {
181+
border: 2px solid #333; /* Highlight the active thumbnail */
182+
opacity: 1; /* Fully visible */
183+
}
184+
185+
/* Scrollbar styling (optional) */
186+
#thumbnail-container::-webkit-scrollbar {
187+
height: 8px;
188+
}
189+
190+
#thumbnail-container::-webkit-scrollbar-thumb {
191+
background-color: #888;
192+
border-radius: 10px;
193+
}
194+
195+
#thumbnail-container::-webkit-scrollbar-thumb:hover {
196+
background-color: #555;
197+
}
91198
</style>

assets/img/gallery/gallery.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[
2+
{
3+
"src": "/assets/img/gallery/lab_photo.jpg",
4+
"caption": "KGML Team (2024)"
5+
},
6+
{
7+
"src": "/assets/img/gallery/Imageomics_Workshop_AAAI_2024.JPG",
8+
"caption": "Imageomics Workshop at AAAI (2024)"
9+
},
10+
{
11+
"src": "/assets/img/gallery/jie_grad_celebration.jpg",
12+
"caption": "Jie’s PhD Defense Celebration (2023)"
13+
},
14+
{
15+
"src": "/assets/img/gallery/Jie's_Defense_celebration_2023.jpg",
16+
"caption": "Jie’s PhD Defense Celebration (2023)"
17+
},
18+
{
19+
"src": "/assets/img/gallery/KGML_Team_2023.jpg",
20+
"caption": "KGML Team (2023)"
21+
},
22+
{
23+
"src": "/assets/img/gallery/Teachers'_Day_2023.JPG",
24+
"caption": "Teachers' Day (2023)"
25+
},
26+
{
27+
"src": "/assets/img/gallery/Medha's_Birthday_2023.JPG",
28+
"caption": "Medha's Birthday (2023)"
29+
},
30+
{
31+
"src": "/assets/img/gallery/Summer_2023.jpg",
32+
"caption": "Team Meetings (2023)"
33+
},
34+
{
35+
"src": "/assets/img/gallery/Amartya's_Birthday_2022_1.jpg",
36+
"caption": "Amartya's Birthday (2022)"
37+
}
38+
39+
]
40+
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)