# @celsowhite/element-in-view

> Detect when an element is visible in the browsers viewport.

Latest version **1.0.1** (published 2019-11-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @celsowhite/element-in-view
pnpm add @celsowhite/element-in-view
yarn add @celsowhite/element-in-view
bun add @celsowhite/element-in-view
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-11-03 |
| First published | 2018-12-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 15 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Celso White |
| Maintainers | celsowhite |
| Keywords | scroll |

## Links

- npm: https://www.npmjs.com/package/@celsowhite/element-in-view
- Repository: https://github.com/celsowhite/element-in-view
- Homepage: https://github.com/celsowhite/element-in-view#readme
- Issues: https://github.com/celsowhite/element-in-view/issues
- npm.io page: https://npm.io/package/@celsowhite/element-in-view

## Recent versions

- 1.0.1 (latest) — 2019-11-03
- 1.0.0 — 2018-12-20

## README

# Element In View

Detect when an element is visible in the browsers viewport.

## Install

###### Node

```
npm install @celsowhite/element-in-view --save
```

###### Browser

Download the library file from dist/element-in-view.umd.js and include it in your sites files.

## Setup

###### Node

```javascript
import elementInView from '@celsowhite/element-in-view';
elementInView(element, elementPart);
```

###### Browser

```html
<script src="dist/element-in-view.umd.js"></script>
<script>
	elementInView(element, elementPart);
</script>
```

## Usage

The script is flexible in that it doesn't assume when/how you are checking if an element is in view. A common use case will be during the window scroll event (see example below). If you use it for scrolling effects then it's recommended to [debounce](https://davidwalsh.name/javascript-debounce-function) the scroll event.

##### Example

```js
const elementToTrack = document.querySelctor('.element');

window.addEventListener('scroll', function() {
	let inView = elementInView(elementToTrack, 'middle');
	console.log(inView); // true/false
});
```

##### Parameters

- `element` {HTML Element} A single element we want to check the position of to see if it is in the viewport.
- `elementPart` {String} The part of the element we track to check if it is in view. Options: top, middle or bottom. Defaults to 'top'.
- `offsetPercentage` {Number} The percentage distance within the window when you want the element to be considered in view. By default, this is 0 so the element will appear when it scrolls into frame.

##### Return

{Bool} True/False

## License

MIT License © [Celso White](https://celsowhite.com)

---
_Source: https://npm.io/package/@celsowhite/element-in-view · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
