diff --git a/src/components/reader/BookReader.tsx b/src/components/reader/BookReader.tsx
index 4467d7b..47cfe45 100644
--- a/src/components/reader/BookReader.tsx
+++ b/src/components/reader/BookReader.tsx
@@ -351,37 +351,31 @@ export function BookReader({ book, pages, onClose }: BookReaderProps) {
setLoadedThumbnails((prev) => ({ ...prev, [pageNumber]: true }));
};
- // Fonction pour scroller jusqu'à la miniature active
+ // Effet pour scroller jusqu'à la miniature active
const scrollToActiveThumbnail = useCallback(() => {
- const container = document.getElementById("thumbnails-container");
- const activeThumbnail = document.getElementById(`thumbnail-${currentPage}`);
- if (container && activeThumbnail) {
- const containerWidth = container.clientWidth;
- const thumbnailLeft = activeThumbnail.offsetLeft;
- const thumbnailWidth = activeThumbnail.clientWidth;
-
- // Centrer la miniature dans le conteneur
- container.scrollLeft = thumbnailLeft - containerWidth / 2 + thumbnailWidth / 2;
+ const thumbnail = document.getElementById(`thumbnail-${currentPage}`);
+ if (thumbnail) {
+ thumbnail.scrollIntoView({
+ behavior: "smooth",
+ block: "nearest",
+ inline: "center",
+ });
}
}, [currentPage]);
- // Effet pour scroller jusqu'à la miniature active au chargement et au changement de page
+ // Effet pour centrer la miniature active quand les contrôles deviennent visibles
useEffect(() => {
- if (showNavigation) {
+ if (showControls) {
scrollToActiveThumbnail();
}
- }, [currentPage, showNavigation, scrollToActiveThumbnail]);
+ }, [showControls, scrollToActiveThumbnail]);
- // Effet pour scroller jusqu'à la miniature active quand la navigation devient visible
+ // Effet pour centrer la miniature active au changement de page
useEffect(() => {
- if (showNavigation) {
- // Petit délai pour laisser le temps à la barre de s'afficher
- const timer = setTimeout(() => {
- scrollToActiveThumbnail();
- }, 100);
- return () => clearTimeout(timer);
+ if (showControls) {
+ scrollToActiveThumbnail();
}
- }, [showNavigation, scrollToActiveThumbnail]);
+ }, [currentPage, showControls, scrollToActiveThumbnail]);
// Fonction pour calculer les miniatures à afficher autour de la page courante
const updateVisibleThumbnails = useCallback(() => {
@@ -504,20 +498,6 @@ export function BookReader({ book, pages, onClose }: BookReaderProps) {