# raf-measure

> Utility for performantly measuring resize, scrolling, and elements entering viewport using rAF.

Latest version **0.0.11** (published 2016-09-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install raf-measure
pnpm add raf-measure
yarn add raf-measure
bun add raf-measure
```

## 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.0.11 |
| Published | 2016-09-09 |
| First published | 2015-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Chad Hietala |
| Maintainers | chadhietala, krisselden |
| Keywords | rAF |

## Links

- npm: https://www.npmjs.com/package/raf-measure
- npm.io page: https://npm.io/package/raf-measure

## Recent versions

- 0.0.11 (latest) — 2016-09-09
- 0.0.10 — 2015-11-12
- 0.0.9 — 2015-10-29
- 0.0.8 — 2015-10-28
- 0.0.7 — 2015-10-27
- 0.0.6 — 2015-10-26
- 0.0.5 — 2015-10-26
- 0.0.3 — 2015-10-26
- 0.0.2 — 2015-10-26
- 0.0.1 — 2015-10-24
- 0.0.0 — 2015-10-24

## README

# rAF Measure

A utility to performantly event scroll and resize events using requestAnimationFrame. This utility also allows you know when a registered element has entered the viewport.

## Usage

### Registering For Scroll Events

```js
import measurer from 'raf-measure';

let measureId = measurer.register('scroll', {
  callback({ scrollTop, scrollLeft }) {
    console.log(scrollTop, scrollLeft);
  }
} /*, optional context */);
```

### Registering For Resize Events

```js
import measurer from 'raf-measure';

let measureId = measurer.register('resize', {
  callback({ height, width }) {
    console.log(height, width);
  }
} /*, optional context */);
```

### Registering For Elements In View Port

```js
import measurer from 'raf-measure';

let measureId = measurer.register('inViewPort', {
  element: document.getElementById('my-div'),
  callback({ height, width }) {
    console.log(height, width);
  }
  // optional hitbox must return a bool
  //, hitbox({elLeft, elTop, elWidth, elHeight}, {clientX, clientY, clientWidth, clientHeight}) {}
} /*, optional context */);
```

### Unregistering Events
```js
import measurer from 'raf-measure';

let measureId = measurer.register('inViewPort', {
  element: document.getElementById('my-div'),
  callback({ height, width }) {
    console.log(height, width);
  }
  // optional hitbox must return a bool
  //, hitbox({elLeft, elTop, elWidth, elHeight}, {clientX, clientY, clientWidth, clientHeight}) {}
} /*, optional context */);

measurer.unregister('inViewPort', measureId);
```

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