fix(web): lecteur défilement vertical — calculer le ratio de position sur la plage de défilement réelle pour ne plus rouvrir au milieu du livre (bug #39)
This commit is contained in:
@ -162,7 +162,7 @@ export function ReaderPage({ bookId }: { bookId: number }) {
|
||||
const changeZoom = useCallback((nextZoom: number | ((currentZoom: number) => number)) => {
|
||||
const stage = document.querySelector(".reader-stage") as HTMLElement | null;
|
||||
const scrollRatioX = stage && stage.scrollWidth > stage.clientWidth ? (stage.scrollLeft + stage.clientWidth / 2) / stage.scrollWidth : 0.5;
|
||||
const scrollRatioY = stage && stage.scrollHeight > stage.clientHeight ? (stage.scrollTop + stage.clientHeight / 2) / stage.scrollHeight : 0.5;
|
||||
const scrollRatioY = stage && stage.scrollHeight > stage.clientHeight ? stage.scrollTop / (stage.scrollHeight - stage.clientHeight) : 0;
|
||||
|
||||
setZoom((currentZoom) => clampReaderZoom(typeof nextZoom === "function" ? nextZoom(currentZoom) : nextZoom));
|
||||
|
||||
@ -170,7 +170,7 @@ export function ReaderPage({ bookId }: { bookId: number }) {
|
||||
requestAnimationFrame(() => {
|
||||
if (!stage) return;
|
||||
stage.scrollLeft = Math.max(0, stage.scrollWidth * scrollRatioX - stage.clientWidth / 2);
|
||||
stage.scrollTop = Math.max(0, stage.scrollHeight * scrollRatioY - stage.clientHeight / 2);
|
||||
stage.scrollTop = Math.max(0, (stage.scrollHeight - stage.clientHeight) * scrollRatioY);
|
||||
});
|
||||
});
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user