# gatsby-plugin-scroll-position

> With this Gatsby Plugin you can easily persist your overflow scroll elements

Latest version **1.3.3** (published 2023-08-09) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install gatsby-plugin-scroll-position
pnpm add gatsby-plugin-scroll-position
yarn add gatsby-plugin-scroll-position
bun add gatsby-plugin-scroll-position
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.3.3 |
| Published | 2023-08-09 |
| First published | 2022-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tobias Høegh |
| Maintainers | tujoworker |
| Keywords | gatsby, gatsby-plugin, layout, provider, wrapper |

## Links

- npm: https://www.npmjs.com/package/gatsby-plugin-scroll-position
- Repository: https://github.com/tujoworker/gatsby-plugin-scroll-position
- Homepage: https://github.com/tujoworker/gatsby-plugin-scroll-position#readme
- Issues: https://github.com/tujoworker/gatsby-plugin-scroll-position/issues
- npm.io page: https://npm.io/package/gatsby-plugin-scroll-position

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.3.3 (latest) — 2023-08-09
- 1.3.2 — 2023-08-09
- 1.3.1 — 2023-08-09
- 1.3.0 — 2023-08-08
- 1.2.1 — 2022-06-28
- 1.2.0 — 2022-06-27
- 1.1.0 — 2022-06-23
- 1.0.0 — 2022-06-23

## README

# Gatsby Plugin for saving overflow scroll position

- Automatic persist CSS overflow scroll position
- Restores position before React has hydrated
- No flickering
- Performant – no event listener
- Uses localStorage by default

Live [Demo](https://tujoworker.github.io/gatsby-plugin-scroll-position/) 🚀 provided by the [example code](https://github.com/tujoworker/gatsby-plugin-scroll-position/tree/main/example-basic).

## How to use and Install

```bash
npm install gatsby-plugin-scroll-position
# or
yarn add gatsby-plugin-scroll-position
```

… and add it to your `gatsby-config.js` file:

```js
exports.plugins = [
  {
    resolve: 'gatsby-plugin-scroll-position',
    options: {
      elements: [
        '.class-selector',
        '#id-selector',
        '[data-testid="test-selector"]',
        {
          selector: '#fallback-position',
          ensureInView: '#fallback-position ul li.scroll-to-me', // ensure this element is in view
        },
      ],
    },
  },
]
```

## `ensureInView` smartness

When nothing is stored in the localStorage, the plugin tries to fulfill the scroll position of the defined selector given in `ensureInView`.

But when the user did scroll before, it will persist its position, as long as it is actually visible.

## How it works

It puts a script at the bottom of every page body in order to restore scroll position before React has hydrated. It stores and restores scroll position on every page transition.

---
_Source: https://npm.io/package/gatsby-plugin-scroll-position · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
