Remembering the user's scroll position (for History.scrollRestoration)

2023/01/15 짧. 1 min read
Remembering the user's scroll position (for History.scrollRestoration)

tl;dr

You can set whether the page should return to where it was originally scrolled when the user presses the back button.

const scrollRestoration = history.scrollRestoration;
if (scrollRestoration === "manual") {
  console.log(
    "If the option is set to manual, the scroll position will not be restored and the user will have to move it manually."
  );
}

Scroll Restoration

This section is about Scroll Restoration, the browser History API for scroll restoration. This API allows you to set whether the page should return to the original scroll position when the user presses the browser’s back button.

The default is auto, and setting this to manual will not restore the scrolled position.

// Restore the user's scroll position on the page.
history.scrollRestoration = "auto"; // default

// The position on the page is not restored and the user must manually scroll to that position.
history.scrollRestoration = "manual";

See also.

Translated with www.DeepL.com/Translator (free version)

관련 포스트가 1개 있어요.

The difference between flex-start and baseline for align-items in a CSS flex box.

짧.
css-flex-box-align-items-attributes cover image
2023/09/24

Difference between flex-start and baseline for align-items in CSS

profile
정현수.
Currently Managed
Currently not managed