From 2bba9f61f8e13edacdafefabca8d77a18eda653f Mon Sep 17 00:00:00 2001 From: aleensd Date: Mon, 25 Nov 2024 15:10:25 +0200 Subject: [PATCH] make thumbnails scrollable --- .../js/components/media-page/MediaPage.scss | 43 ++++++++++++----- .../js/components/media-viewer/ImageViewer.js | 48 +++++++++++++++---- 2 files changed, 69 insertions(+), 22 deletions(-) diff --git a/frontend/src/static/js/components/media-page/MediaPage.scss b/frontend/src/static/js/components/media-page/MediaPage.scss index 1f3a21e..63ade77 100755 --- a/frontend/src/static/js/components/media-page/MediaPage.scss +++ b/frontend/src/static/js/components/media-page/MediaPage.scss @@ -553,9 +553,7 @@ max-width: 90%; } -.slideshow-image{ - position: relative; -} + .slideshow-image img { display: block; @@ -612,33 +610,54 @@ right: 10px; } -.dots { - position: fixed; /* Make the dots container fixed to always be under the image */ +.thumbnail-navigation { + position: fixed; + display: flex; + align-items: center; + justify-content: center; + margin-top: 20px; + gap: 10px; bottom: 10%; left: 50%; transform: translateX(-50%); +} + +.thumbnail-container { display: flex; gap: 10px; + overflow-x: auto; + scroll-behavior: smooth; + max-width: 80%; + padding: 10px 0; + scrollbar-width: none; /* Hide scrollbar for Firefox */ +} + +.thumbnail-container.center-thumbnails { + display: flex; justify-content: center; - z-index: 1000; + overflow: visible; /* No scrollbars for fewer thumbnails */ +} + +.thumbnail-container::-webkit-scrollbar { + display: none; /* Hide scrollbar for Chrome/Safari */ } .thumbnail { - width: 50px; - height: 50px; - object-fit: cover; + width: 60px; + height: 60px; + object-fit: cover; border: 2px solid transparent; border-radius: 5px; cursor: pointer; - transition: all 0.3s ease-in-out; + transition: transform 0.3s ease; } .thumbnail.active { - border-color: rgba(255, 255, 255, 1); + border-color: white; } .thumbnail:hover { - opacity: 0.8; + transform: scale(1.1); } .viewer-container .player-container { diff --git a/frontend/src/static/js/components/media-viewer/ImageViewer.js b/frontend/src/static/js/components/media-viewer/ImageViewer.js index 6d70217..3ce81b3 100755 --- a/frontend/src/static/js/components/media-viewer/ImageViewer.js +++ b/frontend/src/static/js/components/media-viewer/ImageViewer.js @@ -18,6 +18,8 @@ export default function ImageViewer() { const [currentIndex, setCurrentIndex] = useState(0); const [isImgLoading, setIsImgLoading] = useState(true); + const thumbnailRef = React.useRef(); + function onImageLoad() { setImage(getImageUrl()); } @@ -91,6 +93,17 @@ export default function ImageViewer() { window.location.href = mediaPageUrl; }; + const scrollThumbnails = (direction) => { + if (thumbnailRef.current) { + const scrollAmount = 10; + if (direction === 'left') { + thumbnailRef.current.scrollBy({ left: -scrollAmount, behavior: 'smooth' }); + } else if (direction === 'right') { + thumbnailRef.current.scrollBy({ left: scrollAmount, behavior: 'smooth' }); + } + } + }; + return !image ? null : (
@@ -121,16 +134,31 @@ export default function ImageViewer() { › )} -
- {slideshowItems.map((item, index) => ( - {`Thumbnail handleDotClick(index)} - /> - ))} +
+ {slideshowItems.length > 5 && ( + + )} +
+ {slideshowItems.map((item, index) => ( + {`Thumbnail handleDotClick(index)} + /> + ))} +
+ {slideshowItems.length > 5 && ( + + )}