0.1.5 • Published 1 year ago

aliyun-light-clock v0.1.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

介绍

  • 一个使用 requestAnimationFrame 实现setTimeout、setInterval的定时器
  • 支持设置定时器循环次数

使用方式

import {
  setTimeout,
  setInterval,
  clearTimeout,
  clearInterval,
  clock,
  clearClock,
} from '@ali/light-clock';

// Date.now() - creatTime > 60, 执行函数
// 使用 requestAnimationFrame判断
setTimeout(() => {
  console.log(Date.now());
}, 60);

// Date.now() - triggerTime > 60, 执行函数
// 使用 requestAnimationFrame判断
setInterval(() => {
  console.log(Date.now());
}, 60);

// Date.now() - triggerTime > 60, 执行函数,总共执行10次
// 使用 requestAnimationFrame判断

clock(() => {
  console.log(Date.now());
}, 60, 10);