vue首页实现多个倒计时功能

  1. 将时间转化成时分秒
 for (var s = 0; s < this.count_down_list.length; s++) {
              if (this.count_down_list[s].time !== 0) {
                this.live_day = Math.floor(
                  this.count_down_list[s].time / 86400
                );
                this.hour = Math.floor(
                  (this.count_down_list[s].time / 3600) % 24
                );
                this.minute = Math.floor(
                  (this.count_down_list[s].time / 60) % 60
                );
                this.second = Math.floor(this.count_down_list[s].time % 60);  
                this.hour_video_id = this.count_down_list[s].video;

                
                const count_down_dict = {
                  live_day: this.live_day,
                  hour: this.hour,
                  minute: this.minute,
                  second: this.second,
                  video: this.hour_video_id,
                };
                 
                this.hour_minute_second_list.push(count_down_dict);
              }   
            }
  1. 调用倒计时函数
 this.countDowm()

3.倒计时函数

    countDowm() {
      clearInterval(this.promiseTimer);
      this.promiseTimer = setInterval(()=> {
        this.hour_minute_second_list.forEach((self, index)=>{
            if (self.live_day === 0) {
              if (self.hour === 0 && self.minute === 0 && self.second === 0) {
                self.second = 0;
                self.$emit("countDowmEnd", true);
                clearInterval(self.promiseTimer);
              } else if (self.hour == 0 && self.minute !== 0 && self.second === 0) {
                self.second = 59;
                self.minute -= 1;
              } else if (
                self.hour !== 0 &&
                self.minute === 0 &&
                self.second === 0
              ) {
                self.hour -= 1;
                self.minute = 59;
                self.second = 59;
              } else if (
                self.hour !== 0 &&
                self.minute !== 0 &&
                self.second === 0
              ) {
                self.second = 59;
                self.minute -= 1;
              } else {
                self.second -= 1;
              }
            } else {
              if (self.hour == 0 && self.minute == 0 && self.second === 0) {
                self.live_day -= 1;
                self.hour = 23;
                self.minute = 59;
                self.second = 59;
              } else if (
                self.hour !== 0 &&
                self.minute === 0 &&
                self.second === 0
              ) {
                self.hour -= 1;
                self.minute = 59;
                self.second = 59;
              } else if (self.hour == 0 && self.minute !== 0 && self.second === 0) {
                self.second = 59;
                self.minute -= 1;
              } else if (
                self.hour !== 0 &&
                self.minute !== 0 &&
                self.second === 0
              ) {
                self.second = 59;
                self.minute -= 1;
              } else {
                self.second -= 1;
              }
            }
          });
        }, 1000)
   
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值