This class allows you to monitor an HTMLElement and be notified when it enters or exit the viewport.
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
Name | Type | Description | Status | Default |
---|---|---|---|---|
elm | { HTMLElement } | The element to track | required |
Add a callback
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
Remove a callback
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 the tracker