0.0.1 • Published 3 years ago

intersect-events v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

intersect-events

'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.