whenNearViewport

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

Monitor an HTMLElement to be notified when it is near (100vh before or after) the viewport, or in the viewport

Params

  1. $elm*-HTMLElement

    The element to monitor

  2. settings{}Partial<TWhenNearViewportSettings>

    Some settings to tweak the detection behavior

Return

  1. -(Promise<HTMLElement>)

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

Example

import { whenNearViewport } from '@blackbyte/sugar/dom'
whenNearViewport($myCoolHTMLElement).then($elm => {
  // do something with your element that has entered the viewport...
});

Settings

  1. offset`${window.innerHeight}px ${window.innerWidth}px`String

    Some offset

Todo

  • testsnormal