visibility.js
A cross-browser plugin for using the Page Visibility API
Installation
- Download: zip
- Bower:
bower install visibility.js - Git:
git clone https://github.com/alexgibson/visibility.js
Setup
This component can be used as an AMD module, CommonJS module, or a global.
To use create a new Visibility instance, passing the relevant callbacks you need.
var page = new Visibility({
onHidden: hiddenCallback,
onVisible: visibleCallback
});
function hiddenCallback () {
console.log('hidden callback');
}
function visibleCallback () {
console.log('visible callback');
}
Useful methods
isHidden(returns boolean) - manually check to see if the page is hiddenisSupported(returns boolean) - test for Page Visibility API browser supportdestroy- removevisibilitychangeevent listener and unregister callbacks
