Skip to content

Scroll position restoration when scroll-behavior: smooth #284

@yinhx3

Description

@yinhx3

MPA's scroll position restoration behavior: directly position to the previous position when traversing.

When scroll-behavior: auto, navigation API behave the same. But when scroll-behavior: smooth is set, the page will first stay in the same scroll position and then scroll to the previous position with animation.

Worse still, event.scroll() doesn't accept scroll behavior option. So, to cancel this scroll animation, developer need to modify the CSS or fall back to the previous way of handling scrolling, such as recording scrollY in the state.

Reproduction process:

  1. Open this demo (from chrome doc)
  2. Set scroll-behavior: smooth at html element
  3. Make the window small enough to show the scrollbar.
  4. Navigate back and forth on the page.
2025-03-28.150840.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions