Monitor an HTMLElement to be notified when it is in the viewport
Name | Type | Description | Status | Default |
---|---|---|---|---|
elm | { HTMLElement } | The element to monitor | required | |
offset | { Number } | An offset that represent the distance before entering the viewport for the detection | optional | 50 |
Return { (Promise) } The promise that will be resolved when the element is in the viewport
import whenInViewport from 'coffeekraken-sugar/js/dom/whenInViewport'
whenInViewport(myCoolHTMLElement).then((elm) => {
// do something with your element that has entered the viewport...
});
Author : Olivier Bossel [email protected] https://olivierbossel.com