# smooth-scroller

> Simple javascript smooth scrolling library

Latest version **2.2.1** (published 2019-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install smooth-scroller
pnpm add smooth-scroller
yarn add smooth-scroller
bun add smooth-scroller
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2019-10-14 |
| First published | 2016-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | First+Third |
| Maintainers | alaguna, aleperez92, dawnerd, ecwillis, jga, orthagonal1 |
| Keywords | browser, scroll, smooth |

## Links

- npm: https://www.npmjs.com/package/smooth-scroller
- Repository: https://github.com/firstandthird/smooth-scroller
- Issues: https://github.com/firstandthird/smooth-scroller/issues
- npm.io page: https://npm.io/package/smooth-scroller

## Dependencies (1)

- [domassist](https://npm.io/package/domassist.md) ^2.2.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.2.1 (latest) — 2019-10-14
- 2.2.0 — 2019-08-02
- 2.1.0 — 2019-07-02
- 2.0.0 — 2019-04-05
- 1.4.0 — 2017-12-19
- 1.3.0 — 2017-05-17
- 1.2.0 — 2017-05-04
- 1.1.0 — 2017-04-21
- 1.0.1 — 2016-09-22
- 1.0.0 — 2016-09-20

## README

# Smooth-scroller

![npm](https://img.shields.io/npm/v/smooth-scroller.svg)

A tiny, ES6 JavaScript lib to handle smooth scrolling.

## Installation

```sh
npm install smooth-scroller
```

## Usage

See the [full example](./example).

### Javascript

```js
import 'smooth-scroller';
```

### HTML

```html
<a href="#foo" data-smooth>Scroll Smoothly</a>
...some content...
<div id="foo"></div>
```

## Events

Custom events are fired on the element:

| Event                | Description          |
|----------------------|----------------------|
| `smoothscroll:start` | Smooth scroll starts |
| `smoothscroll:end`   | Smooth scroll ends   |

## Methods

Smooth-scroller exposes two methods:

### init(_[selector='[data-smooth]'], [offset=0]_)

Enables smooth-scroller on the elements matched by `selector`.

#### Parameters

`selector='[data-smooth]'` - _{String}_ - Elements that will trigger smooth-scroll call once they're clicked

`offset=0` - _{Number}_ - Controls the distance (negative or positive) between the top border of the element and the top border of the window.

### scroll(target, hash, _[offset=0], [silent=false]_)

`target` - _{string|Element|NodeList}_ - Target element to scroll

`hash` - _{string|Element|NodeList}_ - DOM element ID to scroll

`offset=0` - _{Number}_ - Controls the distance (negative or positive) between the top border of the element and the top border of the window.

`silent=false` - _{Boolean}_ - If enabled, will generate a [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History_API) event

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