js实现活动时间倒计时

//倒计时
    var not3djs = ['活动还剩', '天', '小时', '分', '秒', '活动时间已结束']
    var timer;
    //活动时间单位-秒
    var not3exptime = 60;

    function formatSeconds(n) {
        console.log(n);
        var t = parseInt(n)
        , e = 0
        , s = 0
        , a = 0
        , o = "";
        return n < 60 ? o = t + not3djs[4] : (t >= 60 && (e = parseInt(t / 60),
        t = parseInt(t % 60),
        e >= 60 && (s = parseInt(e / 60),
        e = parseInt(e % 60),
        s >= 24 && (a = parseInt(s / 24),
        s = parseInt(s % 24)))),
        t > -1 && (t = parseInt(t) >= 10 ? t : "0" + t,
        o = "<span>" + t + "</span> " + not3djs[4]),
        e > 0 && (e = parseInt(e) >= 10 ? e : "0" + e,
        o = "<span>" + e + "</span> " + not3djs[3] + o),
        s > 0 && (o = "<span>" + parseInt(s) + "</span> " + not3djs[2] + o),
        a > 0 && (o = "<span>" + parseInt(a) + "</span> " + not3djs[1] + o)),
        not3djs[0] + o
    }
    function CountDown() {
        --not3exptime;
        if(not3exptime >= 0 ){
            msg = formatSeconds(not3exptime);
        }else{
            clearInterval(timer);
            msg = not3djs[5];
        }
        $("#remainTime_1").html(msg)
    }
    timer = setInterval(function(){
        CountDown();
    },1000)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,我可以为您提供一个简单的聚划算倒计时时钟的实现方案。 首先,我们需要一个倒计时时钟的基础框架。您可以使用 HTML、CSS 和 JavaScript 来创建一个简单的倒计时时钟。以下是一个示例代码: HTML 代码: ``` <div class="countdown"> <div class="countdown-item"> <span id="days"></span> <div class="countdown-label">Days</div> </div> <div class="countdown-item"> <span id="hours"></span> <div class="countdown-label">Hours</div> </div> <div class="countdown-item"> <span id="minutes"></span> <div class="countdown-label">Minutes</div> </div> <div class="countdown-item"> <span id="seconds"></span> <div class="countdown-label">Seconds</div> </div> </div> ``` CSS 代码: ``` .countdown { display: flex; justify-content: center; } .countdown-item { margin: 0px 10px; } .countdown-label { font-size: 12px; text-align: center; margin-top: 5px; } .countdown-item span { font-size: 40px; font-weight: bold; display: block; text-align: center; } ``` JavaScript 代码: ``` const countdownElement = document.querySelector('.countdown'); const daysElement = document.querySelector('#days'); const hoursElement = document.querySelector('#hours'); const minutesElement = document.querySelector('#minutes'); const secondsElement = document.querySelector('#seconds'); const countdownDate = new Date('May 10, 2022 20:00:00').getTime(); function updateCountdown() { const now = new Date().getTime(); const distance = countdownDate - 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); daysElement.textContent = days; hoursElement.textContent = hours; minutesElement.textContent = minutes; secondsElement.textContent = seconds; } setInterval(updateCountdown, 1000); ``` 这段代码会创建一个聚划算倒计时时钟,显示距离 2022 年 5 月 10 日晚上 8 点还有多少天、小时、分钟和秒钟。您可以将倒计时结束时间调整为您需要的时间。 希望这个方案对您有所帮助!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

枫叶&情缘

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

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

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

打赏作者

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

抵扣说明:

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

余额充值