Class: CountDown

Tiny.ticker. CountDown

一个高精度、高性能的计时器

new Tiny.ticker.CountDown()

Name Type Description
opts.duration number

每次的时间间隔(ms)

opts.times number

共计次数

Version:
  • 1.1.7
Examples
var cd1 = new Tiny.ticker.CountDown({
  duration: 5e3,
  times: 3,
});
cd1.on('update', function (t) {
  console.log('每五秒打印一次,共打印三次');
});
cd1.on('complete', function (t) {
  console.log('Done');
});
cd1.start();
var cd2 = new Tiny.ticker.CountDown({
  duration: 3e3,
});
cd2.on('update', function (t) {
  console.log('每三秒打印一次,第' + cd2.count + '次');
});
cd2.start();

Members

countnumber

已计次数

Default Value:
  • 0

durationnumber

Default Value:
  • 1000ms

readonlyrunning

计时器是否正在运行

Default Value:
  • false

计时器使用的 Ticker 对象

timesnumber

Default Value:
  • Infinity

Methods

销毁计时器

暂停计时,再次执行 start 会从上次暂停点继续

开始计时,如果是被暂停的计时器,会从上次暂停点继续

停止计时

Events

如果传入 times,则会在计时结束后触发

Name Type Description
time number

调用 CountDown.pause() 后触发

Example
var cd = new Tiny.ticker.CountDown();
cd.on('pause', function(){
  console.log('paused');
});
cd.pause();

调用 CountDown.stop() 后触发

Example
var cd = new Tiny.ticker.CountDown();
cd.on('stop', function(){
  console.log('stop');
});
cd.stop();

每间隔 duration 触发一次

Name Type Description
time number
Example
var cd = new Tiny.ticker.CountDown();
cd.on('update', function(){
  console.log('tick');
});
Documentation generated by JSDoc 3.4.3 on Fri Jul 09 2021 19:32:27 GMT+0800 (CST)