# intersection-events

> Wrapper of IntersectionObserver

Latest version **0.2.9** (published 2019-08-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install intersection-events
pnpm add intersection-events
yarn add intersection-events
bun add intersection-events
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.9 |
| Published | 2019-08-03 |
| First published | 2018-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 21.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ko.Yelie |
| Maintainers | ko-yelie |
| Keywords | IntersectionObserver, scroll, es2015 |

## Links

- npm: https://www.npmjs.com/package/intersection-events
- Repository: https://github.com/ko-yelie/intersection-events
- Homepage: https://github.com/ko-yelie/intersection-events#readme
- Issues: https://github.com/ko-yelie/intersection-events/issues
- npm.io page: https://npm.io/package/intersection-events

## Recent versions

- 0.2.9 (latest) — 2019-08-03
- 0.2.8 — 2019-08-03
- 0.2.7 — 2018-09-04
- 0.2.6 — 2018-08-31
- 0.2.5 — 2018-08-31
- 0.2.4 — 2018-08-31
- 0.2.3 — 2018-08-31
- 0.2.2 — 2018-05-14
- 0.2.1 — 2018-05-09
- 0.2.0 — 2018-05-08
- 0.1.4 — 2018-05-08
- 0.1.3 — 2018-05-01
- 0.1.2 — 2018-04-24
- 0.1.1 — 2018-04-12
- 0.1.0 — 2018-04-12
- … 3 more at https://npm.io/package/intersection-events/versions

## README

# intersection-events
Wrapper of [`IntersectionObserver`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver)

You can detect when **the whole element enters and leaves** window.

## Installation

### ES Modules

[npm](https://www.npmjs.com/package/intersection-events)

```sh
npm i intersection-events
```

```js
import IntersectionEvents from 'intersection-events'
```

### CDN

[unpkg](https://unpkg.com/intersection-events)

```html
<script src="https://unpkg.com/intersection-events"></script>
```

## Usage

[Docs](https://ko-yelie.github.io/intersection-events/docs/class/src/index.js~IntersectionEvents.html)

```js
new IntersectionEvents('.js-target', {
  onEnter: el => {
    // When the whole element enters window
  },
  onLeave: el => {
    // When the whole element leaves window
  }
})
```

```html
<div class="js-target"></div>

<!-- Set threshold only for this element -->
<div class="js-target" data-enter-threshold="0.5" data-leave-threshold="0.5"></div>
```

If you want to detect enter only once, set `isOnce` option to `true`.

```js
new IntersectionEvents('.js-target', {
  onEnter: el => {
    // Do only once
  },
  isOnce: true
})
```

## Browsers support

| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome |
| --------- | --------- | --------- |
| Edge| last version| last version

### Note

If you need to support browsers that do **not** support `IntersectionObserver`, load the **[`IntersectionObserver` polyfill](https://github.com/w3c/IntersectionObserver/tree/master/polyfill).**

If the `IntersectionObserver` polyfill is loaded, browsers support is as follows.

| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>IE / Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari-ios/safari-ios_48x48.png" alt="iOS Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>iOS Safari |
| --------- | --------- | --------- | --------- | --------- |
| IE11, Edge| last version| last version| last version| last version

---

If you want more features, please consider other libraries.

- [Scrollama](https://github.com/russellgoldenberg/scrollama)

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