jq多个倒计时 天、时、分、秒

jq倒计时 天、时、分、秒
这里后端是直接返回的每个倒计时总秒数

$(function(){
		$('.countdown').each(function () {	//countdown是显示时间元素
			let setTimer = null;
			let Time = $(this).attr('time'); //获取每个倒计时的总秒数
			let obj = $(this);
			console.log(Time);
			setTimer = setInterval(function () {
				Time--;
				timer(Time, setTimer, obj);
			}, 1000);
		})
})
function timer(Time, setTimer,obj) {
		if (Time > 0) {
			let int = null;
			let $time = obj;
			Time--;
			console.log(Time);
			letdays = parseInt((Time / 3600) / 24); //计算剩余的天数 
			let hours = parseInt((Time / 3600) % 24); //计算剩余的小时 
			let minutes = parseInt((Time / 60) % 60); // 分
			let seconds = parseInt((Time % 60)); // 秒

			function checkTime(i) { //将0-9的数字前面加上0\.  1变为01
				if (i < 10) {
					return '0' + i;
				} else {
					return i;
				}
			}

			days = checkTime(days);
			hours = checkTime(hours);
			minutes = checkTime(minutes);
			seconds = checkTime(seconds);

			$time.html(`${days}:${hours}:${minutes}:${seconds}`);
		} else {
			clearInterval(setTimer);
			let $time = $('.countdown').html(`活动结束`);
		}
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值