Skip to content

Latest commit

 

History

History
65 lines (37 loc) · 2.01 KB

InViewportStatusChangeDetector.md

File metadata and controls

65 lines (37 loc) · 2.01 KB

InViewportStatusChangeDetector

This class allows you to monitor an HTMLElement and be notified when it enters or exit the viewport.

Example

	const detector = new InViewportStatusChangeDetector(myCoolHTMLElement);
detector.on('enter', (elm) => {
		// the element has entered the viewport
});
detector.on('exit', (elm) => {
		// the element has exit the viewport
});

Author : Olivier Bossel [email protected] https://olivierbossel.com

Constructor

Parameters

Name Type Description Status Default
elm { HTMLElement } The element to track required

Methods

on

Add a callback

Parameters

Name Type Description Status Default
status { String } The status to track (enter exit) required
cb { Function } The callback to add required

Return { InViewportStatusChangeDetector } The instance itself to maintain chainability

off

Remove a callback

Parameters

Name Type Description Status Default
status { String } The status to remove (enter exit) required
cb { Function } The callback to remove required

Return { InViewportStatusChangeDetector } The instance itself to maintain chainability

destroy

Destroy the tracker