Skip to content

heishi1HUMANITY/intersect-events

Repository files navigation

intersect-events

npm version License: MIT

intersect-events add intersection events to dom elements.

Install

npm i --save-dev intersect-events

Usage

import addIntersectEvents from 'intersect-events';

const el: HTMLElement = document.querySelector('#id');
const observer: IntersectionObserver = addIntersectEvents(el);

el.addEventListener('intersect', (e): void => {
  // do something
});
el.addEventListener('intersectEnter', (e): void => {
  // do something
});
el.addEventListener('intersectLeave', (e): void => {
  // do something
});

Syntax

const observer: IntersectionObserver = addIntersectEvents(el[, options]);

Events

el.addEventListener(intersectEvents, callback);

intersect : This event is fired at an Element when the percentage of the target element is visible crosses a threshold.

intersectEnter : This event is fired at an Element when the percentage of the target element is visible crosses a threshold and intersectionObserverEntry.isIntersectiong is true.

intersectLeave : This event is fired at an Element when the percentage of the target element is visible crosses a threshold and intersectionObserverEntry.isIntersectiong is false.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published