vspy
v0.0.10
Published
A simple viewport spy.
Downloads
5
Readme
vspy
A simple viewport spy.
Usage
Factory - accepts 2
parameters:
callback
(required) - function called once for eachelement
, right after it reaches the viewport. It is passed a reference toelement
as a parameter. Once it's called, theelement
gets marked as handled and removed from the pool.options
(optional) - available configuration options include:offset
- custom scroll offset (vertical; default:0
)container
- container to listen forscroll
events on (default:window
)
API:
.observe(target)
- adds elements to the pool. Duplicates and previously handled elements are removed. It accepts either a CSS selector or instances ofElement
,NodeList
andArray
as a parameter..poke()
- triggers targets check.prune()
- a target can be detached at any time, successfully preventing theonscroll
callback from being deregistered. Use this method to notify the instance, that the DOM structure has changed. It accepts no parameters..reset(target)
- marks target as unhandled in the context of the current spy.
Example
Simple spy:
var spy = require('vspy')(callback);
function callback(el) {
console.log(el.nodeName + ' reached the viewport!');
}
spy.observe('.foo');
Other examples:
Installation
$ npm install vspy
Test
$ npm test
Browser support
IE9+