js活动页面倒计时
2017-10-14 本文已影响23人
LuckyS007
- 通过后台返回的活动结束时间和当前服务器时间,这两个时间戳来转换成倒计时
还有活动开始时间(比如距离活动3天就开启倒计时)
//倒计时
function timer(intDiff){
var time = window.setInterval(function(){
var day=0,hour=0,minute=0,second=0;//时间默认值
if(intDiff > 0){
day = Math.floor(intDiff / (60 * 60 * 24));
hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
}else{
location.reload();
}
if (minute <= 9) minute = '0' + minute;
if (second <= 9) second = '0' + second;
$('#s_day').html(day);
$('#s_time').html(hour);
$('#s_minute').html(minute);
$('#s_second').html(second);
intDiff--;
}, 1000);
}
//除以1000化成毫秒,还有三天开始倒计时
var time = currentAct.actEndTime - currentAct.currentTime;
if(time <= 259200000 && time > 0){
timer(time/1000);
}else{
$("#time_show").hide()
}