# gatsby-plugin-smoothscroll

> Polyfilled smooth scrolling behavior and helper function for Gatsby sites.

Latest version **1.2.0** (published 2020-07-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install gatsby-plugin-smoothscroll
pnpm add gatsby-plugin-smoothscroll
yarn add gatsby-plugin-smoothscroll
bun add gatsby-plugin-smoothscroll
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2020-07-21 |
| First published | 2019-09-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Frederick Morin |
| Maintainers | freddydumont |
| Keywords | gatsby, gatsby-plugin, smooth, scroll, smoothscroll, scrollIntoView, polyfill |

## Links

- npm: https://www.npmjs.com/package/gatsby-plugin-smoothscroll
- Repository: https://github.com/freddydumont/gatsby-plugin-smoothscroll
- Homepage: https://github.com/freddydumont/gatsby-plugin-smoothscroll#readme
- npm.io page: https://npm.io/package/gatsby-plugin-smoothscroll

## Dependencies (1)

- [smoothscroll-polyfill](https://npm.io/package/smoothscroll-polyfill.md) ^0.4.4

## Recent versions

- 1.2.0 (latest) — 2020-07-21
- 1.1.0 — 2020-03-10
- 1.0.4 — 2019-12-16
- 1.0.3 — 2019-09-19
- 1.0.2 — 2019-09-19
- 1.0.1 — 2019-09-18

## README

# gatsby-plugin-smoothscroll

Polyfilled smooth scrolling behavior and helper function for Gatsby sites.

The plugin uses [`smoothscroll-polyfill`](https://www.npmjs.com/package/smoothscroll-polyfill) and calls it during the `onClientEntry` Gatsby lifecycle method.

It also includes a `scrollTo` helper function as its main export that you can use as `onClick` event handlers to scroll to the desired element using `{ behavior: 'smooth' }`.

## How to install

```bash
# npm
npm install gatsby-plugin-smoothscroll

# yarn
yarn add gatsby-plugin-smoothscroll
```

## When do I use this plugin?

When you want a polyfilled smooth scroll behavior without having to manually install and call the polyfill.

## Examples of usage

Just add the plugin to the plugins array in your `gatsby-config.js`:

```js
plugins: [`gatsby-plugin-smoothscroll`];
```

If you want to use the helper function, import it:

```js
// this could be in your `pages/index.js` file

import scrollTo from 'gatsby-plugin-smoothscroll';
```

Then use it as an `onClick` event handler:

```jsx
<button onClick={() => scrollTo('#some-id')}>My link</button>
```

Be aware that `scrollTo` uses [`document.querySelector()`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) under the hood, so make sure to respect its syntax.

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