【问题标题】:hilios/jQuery.countdown Destroy instancehilios/jQuery.countdown 销毁实例
【发布时间】:2019-03-30 20:24:03
【问题描述】:

我正在使用这个倒计时插件。 (https://github.com/hilios/jQuery.countdown)

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

【问题讨论】:

    标签: javascript instance countdown destroy


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      尝试使用以下语法:

      $el.countdown('remove');
      

      【讨论】:

      • 但它仍然会触发 countdown.finish 事件
      • 我要销毁所有已初始化的实例
      猜你喜欢
      • 1970-01-01
      • 2019-02-22
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-08
      • 2014-10-01
      相关资源
      最近更新 更多