Teal TealUI

倒计时web/countDown

实现倒计时和正计时效果。

倒计时
隐藏天数
正计时
API

倒计时

import countDown from "web/countDown";

countDown(new Date('2020/1/1'), (days, hours, minutes, seconds, total) => {
    __root__.innerHTML = `还有${days}${hours}小时${minutes}${seconds}秒`;
});

隐藏天数

import countDown from "web/countDown";

countDown(new Date('2020/1/1'), (days, hours, minutes, seconds, total) => {
    __root__.innerHTML = `还有${+days * 24 + +hours}小时${minutes}${seconds}秒`;
});

正计时

import { countUp } from "web/countDown";

countUp(new Date('2011/8/12'), (years, days, hours, minutes, seconds, total) => {
    __root__.innerHTML = `TealUI 已发布:${years}${days}${hours}小时${minutes}${seconds}秒`;
});

API

函数 描述
countDown(end, callback, ...)(end:Date, callback:function, now?:Date):Timer

执行倒计时。

参数 类型 描述 默认值
end* Date
callback* (days: string, hours: string, minutes: string, seconds: string, total: number) => boolean | void
now Date new Date()

返回值

类型:Timer

返回一个计时器,可以通过 clearInterval() 停止倒计时。

示例

countDown(new Date("2020/1/1"), (day, hour, minute, second) => console.log(day, hour, minute, second))

执行倒计时。

countUp(start, callback, ...)(start:Date, callback:function, now?:Date):Timer

执行正计时。

参数 类型 描述 默认值
start* Date
callback* (years: string, days: string, hours: string, minutes: string, seconds: number, total: number) => boolean | void
now Date new Date()

返回值

类型:Timer

返回一个计时器,可以通过 clearInterval() 停止倒计时。

示例

countUp(new Date("2011/8/12"), (years, day, hour, minute, second) => console.log(years, day, hour, minute, second))

执行正计时。