Track when a DOM node enters or leaves the screen.
This module is deprecated. Please consider better alternatives like the Intersection Observer API.
npm install hydrophone
Start tracking a DOM node.
node
: DOM node object. (Node)events
: Object, containing zero or more of the following properties:enters
: Function called when the element enters the viewport. (Function)leaves
: Function called when the element exits the viewport. (Function)
Stop tracking a DOM node.
node
: DOM node object. (Node)
import { add, remove } from 'hydrophone'
var node = document.getElementById('node')
add(node, {
enters: () => {
remove(node) // optional
}
})
See the License file.