0.4.3 • Published 7 years ago
appeared v0.4.3
appeared.js
Track DOM elements as they scroll into and out of view.
Installation
via npm
npm install appearedvia yarn
yarn add appearedUsage
Call appeared() with a config object.
Configuration
The config object can have the following parameters:
elementsHTMLElement[]|HTMLElement|HTMLCollection|NodeList|string[]|stringor a function returning one of the types.appearfunction to call when an element scrolls into view.disappearfunction to call when an element scolls out of view.multipleboolean that indicates if the (dis)appear callbacks should be called successively. Defaults to false.
The Watcher instance
The appeared() function returns either a single or an array of Watcher instances.
Watcher methods:
detroyremoves the event listeners from the window and clears the watcher
Example
import appeared from 'appeared'
appeared({
elements: ['.element', '#special-element'],
multiple: true,
appear: (element, count) => {
// Element scrolled into view
},
disappear: (element, count) => {
// Element scrolled out of view
}
})