【发布时间】:2019-03-30 20:24:03
【问题描述】:
我正在使用这个倒计时插件。 (https://github.com/hilios/jQuery.countdown)
所以我想知道如何在它重新初始化之前销毁所有倒计时实例。
【问题讨论】:
标签: javascript instance countdown destroy
我正在使用这个倒计时插件。 (https://github.com/hilios/jQuery.countdown)
所以我想知道如何在它重新初始化之前销毁所有倒计时实例。
【问题讨论】:
标签: javascript instance countdown destroy
这里是 countdown_start() 方法
start_countdown() {
let self = this;
this.processedMatches.forEach(m => {
let effThis = $(`#span_${m.raceId}`);
let type = effThis.attr("data-raceaType");
if (type !== "POST") {
let nextRace = effThis.attr("data-time");
let raceId = effThis.attr("data-race-id");
let nextYear = moment.tz(nextRace, "GMT+0");
let inst = effThis.countdown(nextYear.toDate())
.on('update.countdown',
function (event) {
let displayDate = event.strftime('%D:%H:%M:%S');
effThis.html(event.strftime(
self.getDisplayFormat(displayDate, effThis))); //'%H:%M:%S'
})
.on('finish.countdown',
function () {
//effThis.html("");
console.log(`count down finished ${raceId}`);
self.slide_carousel();
});
self.countdownInstance.push(inst);
//self.countdownInstance.push(raceId);
}
});
this.countdown_started = true;
}
这是 clear_countdown()
clear_countdown() {
//this.countdownInstance = [];
this.countdownInstance.forEach(inst => {
inst.countdown('remove');
});
//this.countdownInstance = [];
//$('.countSpanMatchUp').countdown('remove');
}
【讨论】:
尝试使用以下语法:
$el.countdown('remove');
【讨论】: