-
倒计时函数
-
{Number} time //倒计时长 默认60
-
start(star,end) 开始函数 star(a)参数a有倒计时的数字,end(b)参数b为ture,结束倒计时调用
-
end(fn) 结束函数 fn结束的回调函数
class downDate {
constructor(time = 60) {
this.record = time
this.time = +time;
this.whether = true;
this.inter = null;
}
start(star, end, befor) {
let _this = this;
_this.whether = false;
befor && befor(_this);
_this.inter = setInterval(function() {
if (_this.time <= 1) {
_this.end();
end && end(_this.whether);
return
}
star && star(–_this.time);
}, 1000)
}
end(fn) {
this.time = this.record
this.whether = true;
clearInterval(this.inter);
fn && fn();
}
}
const downTime = new downDate;export { downTime }
60s倒计时的实现
猜你喜欢
转载自blog.csdn.net/wuwenjie_1997/article/details/100654571
今日推荐
周排行