fix scrolling to position.

This commit is contained in:
Stefan Hardegger
2026-02-23 11:31:36 +01:00
parent f8bf90e0c7
commit 39aaa4a465
2 changed files with 12 additions and 4 deletions

View File

@@ -140,10 +140,14 @@ export default function StoryReadingPage() {
// Calculate target scroll position // Calculate target scroll position
const targetScroll = contentTop + (ratio * contentHeight) - (windowHeight * 0.3); const targetScroll = contentTop + (ratio * contentHeight) - (windowHeight * 0.3);
// Smooth scroll to position // Use smooth scrolling only for shorter stories (< 15 000 words).
// For longer stories the saved position can be 50 000+ px from the top;
// browsers animate smooth-scroll at ~1 0001 500 px/s, so the animation
// would take tens of seconds and often stalls or cancels before finishing.
const scrollBehavior = (story.wordCount ?? 0) < 15000 ? 'smooth' : 'instant';
window.scrollTo({ window.scrollTo({
top: Math.max(0, targetScroll), top: Math.max(0, targetScroll),
behavior: 'smooth' behavior: scrollBehavior
}); });
setHasScrolledToPosition(true); setHasScrolledToPosition(true);

View File

@@ -70,10 +70,14 @@ export default function CollectionReadingView({
// Calculate target scroll position // Calculate target scroll position
const targetScroll = contentTop + (ratio * contentHeight) - (windowHeight * 0.3); const targetScroll = contentTop + (ratio * contentHeight) - (windowHeight * 0.3);
// Smooth scroll to position // Use smooth scrolling only for shorter stories (< 15 000 words).
// For longer stories the saved position can be 50 000+ px from the top;
// browsers animate smooth-scroll at ~1 0001 500 px/s, so the animation
// would take tens of seconds and often stalls or cancels before finishing.
const scrollBehavior = (story.wordCount ?? 0) < 15000 ? 'smooth' : 'instant';
window.scrollTo({ window.scrollTo({
top: Math.max(0, targetScroll), top: Math.max(0, targetScroll),
behavior: 'smooth' behavior: scrollBehavior
}); });
setHasScrolledToPosition(true); setHasScrolledToPosition(true);