evaseemefly / ticktock.js

js定时器

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JS定时器

用于指定时间区间/倒计时的定时器

解决前端定时器执行时间不准确的问题,内部单独计时后与指定服务器开始时间进行校准

API

Classes

TickTock

Functions

start(sTime, eTime)

开始运行定时器

stop()

停止定时器

count(seconds)

运行倒计时

whenTick(fn, ctx)string

注册tick事件

whenEnd(fn, ctx)string

注册tick事件

when(time, fn, ctx)string

倒计时剩余时间为time时 有且只触发一次 -> 如果7min注册一次, 5min注册一次, 开始倒计时为4min则都不会被触发/p>

TickTock

Kind: global class

new TickTock()

指定开始时间-结束时间 区间内进行倒计时 指定时间点运行,每秒运行,结束运行

new TickTock(name, type)

Param Type Description
name string 定时器标识名称
type string 运行类型: ['timer', 'counter'] timer定时器 counter倒计时器

start(sTime, eTime)

开始运行定时器

Kind: global function Access: public

Param Type Description
sTime string 开始时间 _服务器时间
eTime string 结束时间

stop()

停止定时器

Kind: global function Access: public

count(seconds)

运行倒计时

Kind: global function Access: public

Param Type
seconds number

whenTick(fn, ctx) ⇒ string

注册tick事件

Kind: global function Returns: string - handlerId Access: public

Param Type
fn func
ctx obj

whenEnd(fn, ctx) ⇒ string

注册tick事件

Kind: global function Returns: string - handlerId Access: public

Param Type
fn func
ctx obj

when(time, fn, ctx) ⇒ string

倒计时剩余时间为time时 有且只触发一次 -> 如果7min注册一次, 5min注册一次, 开始倒计时为4min则都不会被触发

Kind: global function Returns: string - handlerId Access: public

Param Type
time string
fn func
ctx obj

注意事项

  1. 倒计时使用count()运行,定时器使用start()运行

  2. 倒计时不应该监听when(time)时间点,因为count没有时间的概念只会倒计时秒数

  3. timer when(time),如果当前起始时间处于多个time之后,改为start时去除过期time

About

js定时器


Languages

Language:JavaScript 100.0%