live-on-stage2.0.19 • Public • Published
Live on Stage
High performance tracking of DOM elements entering and leaving the viewport.
npm install live-on-stage --save
Start tracking an element
Start tracking a DOM element by providing it to
startTrackingElement. A second argument,
options, is an optional object with event callbacks and other properties.
;const trackingId = ;
onEnter: function: Fires when element enters the viewport (becomes visible). Opposite:
onLeave: function: Fires when element leaves the viewport (becomes non-visible). Opposite:
onBeginLeave: function: Fires when the element begins to leaves the viewport. Opposite:
onCompleteEnter: function: Fires when an element completely enters the viewport. Opposite:
onMeasure: function: Fires when an element is measured - usually on tracking start or screen resize.
onScroll: function: Fires when the screen is scrolled.
buffer: number: Size, in pixels, to add to each side of the element's calculated bounding box.
Callbacks are provided one argument,
elementData, which can be used to query the positional status of an element:
dom: HTMLElement: The DOM element as provided to
left: number: Absolute bounding box measurements relative to document.
truewhen element is positioned off given viewport side.
truewhen element is completely within viewport side.
Stop tracking an element
Manually check scroll position