whenInViewport

Type:Function
Status:stable
Since:1.0.0
Platform:js
@blackbyte.sugar.js.dom.when

Monitor an HTMLElement to be notified when it is in the viewport

Params

  1. $elm*-HTMLElement

    The element to monitor

  2. settings{}Partial<TWhenInViewportSettings>

    Some settings to tweak the detection behavior

Return

  1. -(SPromise<HTMLElement>)

    The promise that will be resolved when the element is in the viewport

Example

import { whenInViewport } from '@blackbyte/sugar/dom'
const promise = whenInViewport($myCoolHTMLElement).then((elm) => {
  // do something with your element that has entered the viewport...
});
// when you want to stop listening
promise.cancel();

Settings

  1. offset’10px’String

    An offset to detect sooner or later the element entering in the viewport

  2. [whenIn]*-Function

    A callback function to call when the element enter the viewport

  3. [whenOut]*-Function

    A callback function to call when the element leave the viewport

  4. oncetrueBoolean

    Specify if the promise should be resolved only once (the first time the element enter the viewport)

Todo

  • testsnormal