Class: CountDown

Bling.ticker. CountDown

new Bling.ticker.CountDown(opts)

bling/ticker/CountDown.js, line 38

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

Name Type Description
opts object
Name Type Default Description
duration number 1000 optional

每次的时间间隔(ms)

times number Infinity optional

共计次数

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

Extends

  • EventEmitter

Members

readonlyrunning

计时器是否正在运行

Default Value:
  • false

Methods

destroy()

bling/ticker/CountDown.js, line 155

销毁计时器

pause()

bling/ticker/CountDown.js, line 140

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

start()

bling/ticker/CountDown.js, line 110

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

stop()

bling/ticker/CountDown.js, line 147

停止计时

Events

complete

bling/ticker/CountDown.js, line 62

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

Name Type Description
time number

pause

bling/ticker/CountDown.js, line 68

调用 CountDown.pause() 后触发

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

stop

bling/ticker/CountDown.js, line 80

调用 CountDown.stop() 后触发

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

update

bling/ticker/CountDown.js, line 50

每间隔 duration 触发一次

Name Type Description
time number
Example
const cd = new Bling.ticker.CountDown();
cd.on('update', function(){
  console.log('tick');
});
Documentation generated by JSDoc 3.4.3 on Thu Jul 09 2020 18:39:28 GMT+0800 (CST)