element-in-viewport

1.2.4 • Public • Published

element-in-viewport

npm Build Status GitHub license

An async module that resolves when an element has entered the viewport at a certain percentage, using the Intersection Observer API.

Polyfilled with the Intersection Observer Polyfill

With the polyfill, IntersectionObserver has been tested and known to work in the following browsers:

Chrome
Firefox
Safari
6+
Edge
Internet Explorer
7+
Opera
Android
4.4+

Install:

npm i -S element-in-viewport

Example Usage:

import elementInViewport from 'element-in-viewport';

(async () => {

    const targetElement = document.querySelector('#targetElement');

    const entry = await elementInViewport(targetElement, 0);

    alert(`Intersection in Viewport Detected at IntersectionRatio ${entry.intersectionRatio}`);

})();

Package Sidebar

Install

npm i element-in-viewport

Weekly Downloads

1,297

Version

1.2.4

License

MIT

Unpacked Size

8.64 kB

Total Files

5

Last publish

Collaborators

  • smrubin