In-post event gallery block + lightbox; mobile polish
- Reusable "Photos from the event" grid (shows 5 thumbnails + "+N more") that opens a full-screen lightbox (arrows / keyboard / swipe / Esc); added to the Meet Student Slovenia 2024 post as the pattern - New css/components/_lightbox.css + setupLightbox() in main.js (injects one shared overlay, wires any .js-lightbox grid) - Mobile polish: gallery albums go single-column on phones, two on tablets; event-gallery grid 3-up on mobile; lightbox sizing/controls tuned for small screens Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
24c77e6171
commit
1f5e031be9
|
|
@ -0,0 +1,75 @@
|
|||
/* ==========================================================================
|
||||
Reusable photo gallery block ("Photos from the event") + lightbox
|
||||
Drop a .event-gallery-grid.js-lightbox anywhere; main.js wires the viewer.
|
||||
========================================================================== */
|
||||
.event-gallery { margin: 48px 0 8px; }
|
||||
.event-gallery-title {
|
||||
font-size: 22px; font-weight: 700; color: #101828; margin: 0 0 16px;
|
||||
}
|
||||
.event-gallery-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 8px;
|
||||
}
|
||||
.eg-thumb {
|
||||
padding: 0; border: none; background: #EEF2F4;
|
||||
border-radius: 8px; overflow: hidden; cursor: pointer;
|
||||
aspect-ratio: 1; position: relative; display: block;
|
||||
}
|
||||
.eg-thumb img {
|
||||
width: 100%; height: 100%; object-fit: cover; display: block;
|
||||
transition: transform 0.4s ease;
|
||||
}
|
||||
.eg-thumb:hover img { transform: scale(1.06); }
|
||||
.eg-thumb:focus-visible { outline: 2px solid #2D738C; outline-offset: 2px; }
|
||||
.eg-thumb.is-hidden { display: none; }
|
||||
.eg-more {
|
||||
position: absolute; inset: 0; z-index: 2;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
background: rgba(9, 18, 26, 0.55);
|
||||
color: #FFFFFF; font-size: 18px; font-weight: 700;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* ---------- Full-screen lightbox (injected once by main.js) ---------- */
|
||||
.lightbox {
|
||||
position: fixed; inset: 0; z-index: 2000;
|
||||
display: none; align-items: center; justify-content: center;
|
||||
background: rgba(9, 18, 26, 0.93); padding: 24px;
|
||||
}
|
||||
.lightbox.is-open { display: flex; }
|
||||
.lightbox-img {
|
||||
max-width: 92vw; max-height: 82vh; object-fit: contain;
|
||||
border-radius: 6px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
|
||||
user-select: none; -webkit-user-drag: none;
|
||||
}
|
||||
.lightbox-close, .lightbox-prev, .lightbox-next {
|
||||
position: absolute; background: rgba(255, 255, 255, 0.12);
|
||||
color: #FFFFFF; border: none; cursor: pointer; border-radius: 50%;
|
||||
width: 48px; height: 48px; font-size: 24px; line-height: 1;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
.lightbox-close:hover, .lightbox-prev:hover, .lightbox-next:hover { background: rgba(255, 255, 255, 0.25); }
|
||||
.lightbox-close { top: 20px; right: 20px; font-size: 28px; }
|
||||
.lightbox-prev { left: 20px; top: 50%; transform: translateY(-50%); }
|
||||
.lightbox-next { right: 20px; top: 50%; transform: translateY(-50%); }
|
||||
.lightbox-caption {
|
||||
position: absolute; bottom: 18px; left: 0; right: 0;
|
||||
text-align: center; color: rgba(255, 255, 255, 0.85);
|
||||
font-size: 14px; padding: 0 24px;
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.event-gallery { margin: 36px 0 8px; }
|
||||
.event-gallery-title { font-size: 19px; margin: 0 0 12px; }
|
||||
.event-gallery-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.lightbox { padding: 12px; }
|
||||
.lightbox-img { max-width: 96vw; max-height: 80vh; }
|
||||
.lightbox-prev { left: 8px; }
|
||||
.lightbox-next { right: 8px; }
|
||||
.lightbox-close { top: 12px; right: 12px; }
|
||||
.lightbox-caption { font-size: 12.5px; bottom: 12px; }
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
@import 'components/_buttons.css';
|
||||
@import 'components/_cards.css';
|
||||
@import 'components/_lang-banner.css';
|
||||
@import 'components/_lightbox.css';
|
||||
|
||||
/* 4. Page-specific Styles */
|
||||
@import 'pages/_home.css';
|
||||
|
|
|
|||
|
|
@ -86,10 +86,17 @@
|
|||
.album-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: #D0D5DD; }
|
||||
.album-meta .read-link { color: #2D738C; font-weight: 600; }
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.gallery-albums { grid-template-columns: 1fr 1fr; gap: 18px 14px; padding: 24px 16px 72px; }
|
||||
.album-cover { height: 150px; }
|
||||
.album-info { padding: 12px 12px 14px; }
|
||||
.album-info h3 { font-size: 15px; }
|
||||
.cover-more-badge { font-size: 17px; }
|
||||
/* Tablets / large phones: two clear columns */
|
||||
@media (max-width: 768px) and (min-width: 561px) {
|
||||
.gallery-albums { grid-template-columns: 1fr 1fr; gap: 20px 16px; }
|
||||
.album-cover { height: 185px; }
|
||||
}
|
||||
/* Phones: one full-width column so each album reads clearly */
|
||||
@media (max-width: 560px) {
|
||||
.gallery-hero { padding: 44px 20px 32px; }
|
||||
.gallery-albums { grid-template-columns: 1fr; gap: 22px; padding: 22px 16px 64px; }
|
||||
.album-cover { height: 210px; }
|
||||
.album-info { padding: 13px 14px 15px; }
|
||||
.album-info h3 { font-size: 16px; }
|
||||
.cover-more-badge { font-size: 20px; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -319,6 +319,24 @@
|
|||
|
||||
</div>
|
||||
|
||||
<section class="event-gallery">
|
||||
<h2 class="event-gallery-title">Photos from the event</h2>
|
||||
<div class="event-gallery-grid js-lightbox">
|
||||
<button type="button" class="eg-thumb" data-full="../../../images/event4-img-1.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-1.webp" alt="Meet Student Slovenia 2024 — photo 1"></button>
|
||||
<button type="button" class="eg-thumb" data-full="../../../images/event4-img-2.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-2.webp" alt="Meet Student Slovenia 2024 — photo 2"></button>
|
||||
<button type="button" class="eg-thumb" data-full="../../../images/event4-img-3.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-3.webp" alt="Meet Student Slovenia 2024 — photo 3"></button>
|
||||
<button type="button" class="eg-thumb" data-full="../../../images/event4-img-4.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-4.webp" alt="Meet Student Slovenia 2024 — photo 4"></button>
|
||||
<button type="button" class="eg-thumb" data-full="../../../images/event4-img-5.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-5.webp" alt="Meet Student Slovenia 2024 — photo 5"><span class="eg-more">+7</span></button>
|
||||
<button type="button" class="eg-thumb is-hidden" data-full="../../../images/event4-img-6.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-6.webp" alt="Meet Student Slovenia 2024 — photo 6"></button>
|
||||
<button type="button" class="eg-thumb is-hidden" data-full="../../../images/event4-img-7.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-7.webp" alt="Meet Student Slovenia 2024 — photo 7"></button>
|
||||
<button type="button" class="eg-thumb is-hidden" data-full="../../../images/event4-img-8.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-8.webp" alt="Meet Student Slovenia 2024 — photo 8"></button>
|
||||
<button type="button" class="eg-thumb is-hidden" data-full="../../../images/event4-img-9.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-9.webp" alt="Meet Student Slovenia 2024 — photo 9"></button>
|
||||
<button type="button" class="eg-thumb is-hidden" data-full="../../../images/event4-img-10.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-10.webp" alt="Meet Student Slovenia 2024 — photo 10"></button>
|
||||
<button type="button" class="eg-thumb is-hidden" data-full="../../../images/event4-img-11.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-11.webp" alt="Meet Student Slovenia 2024 — photo 11"></button>
|
||||
<button type="button" class="eg-thumb is-hidden" data-full="../../../images/event4-img-12.webp" data-caption="Meet Student Slovenia 2024"><img loading="lazy" decoding="async" src="../../../images/event4-img-12.webp" alt="Meet Student Slovenia 2024 — photo 12"></button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer class="article-footer">
|
||||
<hr>
|
||||
<div class="author-share-section">
|
||||
|
|
|
|||
76
main.js
76
main.js
|
|
@ -833,6 +833,81 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ===================================================================
|
||||
* REUSABLE LIGHTBOX (for .event-gallery-grid.js-lightbox blocks)
|
||||
* ===================================================================
|
||||
*/
|
||||
function setupLightbox() {
|
||||
var grids = document.querySelectorAll('.js-lightbox');
|
||||
if (!grids.length) return;
|
||||
|
||||
var lb = document.createElement('div');
|
||||
lb.className = 'lightbox';
|
||||
lb.setAttribute('role', 'dialog');
|
||||
lb.setAttribute('aria-label', 'Photo viewer');
|
||||
lb.setAttribute('aria-hidden', 'true');
|
||||
lb.innerHTML =
|
||||
'<button type="button" class="lightbox-close" aria-label="Close">×</button>' +
|
||||
'<button type="button" class="lightbox-prev" aria-label="Previous">❮</button>' +
|
||||
'<img class="lightbox-img" src="" alt="">' +
|
||||
'<button type="button" class="lightbox-next" aria-label="Next">❯</button>' +
|
||||
'<div class="lightbox-caption"></div>';
|
||||
document.body.appendChild(lb);
|
||||
|
||||
var img = lb.querySelector('.lightbox-img');
|
||||
var cap = lb.querySelector('.lightbox-caption');
|
||||
var group = [];
|
||||
var idx = 0;
|
||||
|
||||
function render() {
|
||||
var it = group[idx];
|
||||
img.setAttribute('src', it.full);
|
||||
img.setAttribute('alt', it.caption || '');
|
||||
cap.textContent = (it.caption || '') + (group.length > 1 ? ' (' + (idx + 1) + '/' + group.length + ')' : '');
|
||||
}
|
||||
function open(grid, start) {
|
||||
group = Array.prototype.map.call(grid.querySelectorAll('.eg-thumb'), function (b) {
|
||||
return { full: b.getAttribute('data-full'), caption: b.getAttribute('data-caption') || '' };
|
||||
});
|
||||
idx = start;
|
||||
render();
|
||||
lb.classList.add('is-open');
|
||||
lb.setAttribute('aria-hidden', 'false');
|
||||
document.documentElement.style.overflow = 'hidden';
|
||||
}
|
||||
function close() {
|
||||
lb.classList.remove('is-open');
|
||||
lb.setAttribute('aria-hidden', 'true');
|
||||
document.documentElement.style.overflow = '';
|
||||
img.setAttribute('src', '');
|
||||
}
|
||||
function step(d) { idx = (idx + d + group.length) % group.length; render(); }
|
||||
|
||||
grids.forEach(function (grid) {
|
||||
grid.querySelectorAll('.eg-thumb').forEach(function (b, i) {
|
||||
b.addEventListener('click', function () { open(grid, i); });
|
||||
});
|
||||
});
|
||||
lb.querySelector('.lightbox-close').addEventListener('click', close);
|
||||
lb.querySelector('.lightbox-prev').addEventListener('click', function () { step(-1); });
|
||||
lb.querySelector('.lightbox-next').addEventListener('click', function () { step(1); });
|
||||
lb.addEventListener('click', function (e) { if (e.target === lb) close(); });
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (!lb.classList.contains('is-open')) return;
|
||||
if (e.key === 'Escape') close();
|
||||
else if (e.key === 'ArrowLeft') step(-1);
|
||||
else if (e.key === 'ArrowRight') step(1);
|
||||
});
|
||||
// Swipe on touch devices
|
||||
var sx = 0;
|
||||
lb.addEventListener('touchstart', function (e) { sx = e.changedTouches[0].clientX; }, { passive: true });
|
||||
lb.addEventListener('touchend', function (e) {
|
||||
var dx = e.changedTouches[0].clientX - sx;
|
||||
if (Math.abs(dx) > 40) step(dx < 0 ? 1 : -1);
|
||||
}, { passive: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* ===================================================================
|
||||
* HUB USE-CASE CAROUSEL (auto-scrolling)
|
||||
|
|
@ -863,5 +938,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
setupLanguageSuggestion();
|
||||
setupNewsletter();
|
||||
setupHubCarousel();
|
||||
setupLightbox();
|
||||
|
||||
});
|
||||
Loading…
Reference in New Issue