___ _ ___ ___ _ | _ (_)__ ___/ __| _ \/_\ | _/ / _/ _ \__ \ _/ _ \ |_| |_\__\___/___/_|/_/ \_\ A PicoSSG tool

Scroll

PicoSPA allows you to store and restore scroll positions across page loads, maintaining the user's scroll position in both the window and specific scrollable elements.

Why? You may ask. For example for pages, where you have a "load more" button, or a filter that changes the content of the page, you want to keep the scroll position when the new page loads, so the user can continue reading where they left off. Other use cases might be "like", "subscribe", "add to cart" buttons that change the content of the page, but you want to keep the scroll position.

Try it Out 👏

1️⃣ Try first

2️⃣ Try second

3️⃣ Try this too:

How To Use

Add the script to your page and call restore with a unique page key:

<script src="https://cdn.jsdelivr.net/npm/@pic0/spa@2026.1.12/_dist/picospa.min.js"></script>
<script>
  picospa.scroll.restore({key: 'my-page-key'});
</script>

This will:

Scrollable Elements

You can also restore scroll positions for specific scrollable elements:

picospa.scroll.restore({key: 'my-page-key', otherNodes: [
  '#sidebar',
  '.content-area',
  '[data-scrollable]'
]});

Both window and element scroll positions will be restored.

Storage

Scroll positions are stored in sessionStorage using the provided page key:

Important Notes