fix scrolling to position.
This commit is contained in:
@@ -140,10 +140,14 @@ export default function StoryReadingPage() {
|
||||
// Calculate target scroll position
|
||||
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 000–1 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({
|
||||
top: Math.max(0, targetScroll),
|
||||
behavior: 'smooth'
|
||||
behavior: scrollBehavior
|
||||
});
|
||||
|
||||
setHasScrolledToPosition(true);
|
||||
|
||||
@@ -70,10 +70,14 @@ export default function CollectionReadingView({
|
||||
// Calculate target scroll position
|
||||
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 000–1 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({
|
||||
top: Math.max(0, targetScroll),
|
||||
behavior: 'smooth'
|
||||
behavior: scrollBehavior
|
||||
});
|
||||
|
||||
setHasScrolledToPosition(true);
|
||||
|
||||
Reference in New Issue
Block a user