0.0.3 • Published 2 years ago

interval-center v0.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Interval-Center

简单的定时器任务管理中心,具备切后台自动暂停,切回自动重启功能

安装

  • es module
  • npm install
  • cdn iife
npm i -S interval-center

api

api name参数描述
add(task,time)task:任务 time:延迟时间添加一个定时任务
start(immediately=false)immediately:是否立即执行开始执行定时器
remove(task)task:任务移除具体某个定时任务
stop(force=false)force:强力暂停,页面从后台切回也不会restart是否暂定所有定时任务
clear()清空所有定时任务监听

使用

        const ic = new IntervalCenter();

        ic.add(sayHello, 1000).start(true)

        function sayHello() {
            document.body.querySelectorAll('*').length;
            console.log("hello friend");
            const helloText = document.createElement('p');
            helloText.style.textAlign = 'center'
            helloText.innerText = `hello friend ${Date.now()}`
            document.body.append(helloText)
            // ic.stop(true)
        }

细节异步demo代码

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago