Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve smooth scroll behavior to prevent button flickering #1975

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

hexart
Copy link
Contributor

@hexart hexart commented Mar 9, 2025

Smooth Scroll Button Behavior Fix

This PR addresses the issue where the scroll button briefly reappears during smooth scrolling animation.

Problem

When using behavior: 'smooth' for scrolling, the scroll button would flicker due to handleScroll being triggered during the animation process, causing showScrollButton to be set to true before reaching the bottom.

Solution

  1. Added an isScrolling state to track scroll animation status
  2. Created a checkScrollEnd function at component level to monitor actual scroll position and detect when scrolling has completely stopped
    • Placing this function at component level improves performance by avoiding function recreation on each button click
  3. Enhanced both scrollToBottom and scrollToPosition functions to properly handle smooth scrolling:
    • Setting isScrolling state to true at start
    • Hiding scroll button during animation
    • Using checkScrollEnd to detect end of animation
    • Updating button visibility based on final position

Edge Case Handling

The solution also handles user interaction during scroll animation. When users interrupt auto-scroll with mouse wheel, the scroll button visibility is immediately updated when scrolling stops, accurately reflecting the current position without requiring additional scroll input.

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. frontend Pertains to the frontend. labels Mar 9, 2025
@hexart hexart marked this pull request as draft March 9, 2025 17:07
@hexart hexart marked this pull request as ready for review March 10, 2025 03:12
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Pertains to the frontend. size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant