0.0.10 • Published 11 years ago
vspy v0.0.10
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 toelementas a parameter. Once it's called, theelementgets 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 forscrollevents 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,NodeListandArrayas a parameter..poke()- triggers targets check.prune()- a target can be detached at any time, successfully preventing theonscrollcallback 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 vspyTest
$ npm testBrowser support
IE9+
