功能点:3秒倒计时自动跳转指定页面

data() {
    return {
      title: "支付结果",
      count: "" //倒计时
    };
  },
created() {
  this.threeGo();
},
methods: {
    threeGo() {
      const TIME_COUNT = 3;
      if (!this.timer) {
        this.count = TIME_COUNT;
        this.show = false;
        this.timer = setInterval(() => {
          if (this.count > 1 && this.count <= TIME_COUNT) {
            this.count--;
          } else {
            this.show = true;
            clearInterval(this.timer);
            this.timer = null;
            //跳转的页面写在此处
            
          }
        }, 1000);
      }
    }
}
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是三个页面的设计,分别实现不同的倒计时效果: 第一个页面倒计时指定时间,每更新倒计时时间。 ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>倒计时页面1</title> <script> // 获取指定时间(2021年12月31日23时59分59)的时间戳 const targetTime = new Date('2021-12-31 23:59:59').getTime(); // 更新倒计时时间的函数 function updateCountdown() { const now = new Date().getTime(); const distance = targetTime - now; // 计算倒计时时间 const days = Math.floor(distance / (1000 * 60 * 60 * 24)); const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); const seconds = Math.floor((distance % (1000 * 60)) / 1000); // 更新页面上的倒计时时间 document.getElementById('countdown').innerHTML = `${days}天 ${hours}小时 ${minutes}分 ${seconds}`; // 每更新一次倒计时时间 setTimeout(updateCountdown, 1000); } </script> </head> <body onload="updateCountdown()"> <h1>倒计时页面1</h1> <p>距离2022年元旦还有:</p> <p id="countdown"></p> </body> </html> ``` 第二个页面倒计时一定时间,每更新倒计时时间。 ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>倒计时页面2</title> <script> // 设置倒计时时间为60 const targetTime = 60 * 1000; // 更新倒计时时间的函数 function updateCountdown() { const now = new Date().getTime(); const distance = targetTime - (now - startTime); // 计算倒计时时间 const seconds = Math.floor(distance / 1000); // 更新页面上的倒计时时间 document.getElementById('countdown').innerHTML = `${seconds}`; // 如果倒计时时间为0,停止倒计时 if (distance <= 0) { clearInterval(intervalId); document.getElementById('countdown').innerHTML = '时间到!'; } } // 记录倒计时开始时间 const startTime = new Date().getTime(); // 每更新一次倒计时时间 const intervalId = setInterval(updateCountdown, 1000); </script> </head> <body> <h1>倒计时页面2</h1> <p>距离倒计时结束还有:</p> <p id="countdown"></p> </body> </html> ``` 第三个页面倒计时指定时间倒计时结束后自动跳转到另一个页面。 ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>倒计时页面3</title> <script> // 获取指定时间(2022年1月1日0时0分0)的时间戳 const targetTime = new Date('2022-01-01 00:00:00').getTime(); // 更新倒计时时间的函数 function updateCountdown() { const now = new Date().getTime(); const distance = targetTime - now; // 计算倒计时时间 const seconds = Math.floor(distance / 1000); // 更新页面上的倒计时时间 document.getElementById('countdown').innerHTML = `${seconds}`; // 如果倒计时时间为0,跳转指定页面 if (distance <= 0) { clearInterval(intervalId); window.location.href = 'http://example.com/countdown-end'; } } // 每更新一次倒计时时间 const intervalId = setInterval(updateCountdown, 1000); </script> </head> <body> <h1>倒计时页面3</h1> <p>距离2022年元旦还有:</p> <p id="countdown"></p> </body> </html> ``` 以上三个页面可以分别保存为 HTML 文件,通过在浏览器中打开查看效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

落花流雨

你的鼓励将是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值