hilios / jQuery.countdown销毁实例

时间:2018-10-26 06:17:45

标签: javascript instance countdown destroy

我正在使用此倒数插件。 (https://github.com/hilios/jQuery.countdown

所以我想知道如何在重新初始化自己之前销毁所有倒计时实例。

2 个答案:

答案 0 :(得分:0)

尝试使用以下语法:

$el.countdown('remove');

答案 1 :(得分:0)

这是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');
        }