visibility-once

0.4.0 • Public • Published

visibility-once

Wrapper for the Page Visibility API, and execute callback function once. It's no need to stop/unbind compared with Visibility.js. Otherwise, you can set a number to limit max callback function(use a Queue).

example

import visibility from 'visibility-once';
 
const { run: runIfVisible } = visibility().max(3);
 
runIfVisible(() => {
    // run if current page is visible, and store 3 callback functions at most
    // 如果当前页面**是**用户正在浏览的标签页才执行,待执行函数最多保存3个,超过会将最早的去掉
});
 
const { run: runIfHidden } = visibility(false).max(5);
 
runIfHidden(() => {
    // run if current page is hidden, and store 5 callback functions at most
    // 如果当前页面**非**用户正在浏览的标签页才执行,待执行函数最多保存5个,超过会将最早的去掉
});

Package Sidebar

Install

npm i visibility-once

Weekly Downloads

1

Version

0.4.0

License

MIT

Unpacked Size

58.1 kB

Total Files

10

Last publish

Collaborators

  • tianyn1990