项目每条数据都加倒计时:
1.根据时间戳(秒数)计算倒计时
setClock:function(time){
var that=this, sec= parseInt(time) , clockCount={}, strTimer="";
clockCount=setInterval(function(){ if(sec==0){
//$(".js-count-down").html("活动已经结束");
clearInterval(clockCount);
return false;
}
strTimer = that.secondToDate(sec);
//$(".js-count-down").html(strTimer);
sec--;
},1000) },
secondToDate:function(result){
var h = Math.floor(result / 3600) < 10 ? '0'+Math.floor(result / 3600) :Math.floor(result / 3600);
var m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
var s = Math.floor((result % 60)) < 10 ? '0' +Math.floor((result % 60)) : Math.floor((result % 60));
if(h==0){ result = m + ":" + s; }else{ result = h+':'+m + ":" + s } return result;
},
2.倒计时(分:秒)(参数输入多少分)
resetTime(timestamp){//30min倒计时 30
var timer=null;
var t=timestamp;
var m=0;
var s=0;
m=Math.floor(t/60%60);
m<10&&(m='0'+m);
s=Math.floor(t%60);
let countDown=()=>{
s--;
s<10&&(s='0'+s);
if(s.length>=3){
s=59;
m="0"+(Number(m)-1);
}
if(m.length>=3){
m='00';
s='00';
clearInterval(timer);
}
_this.remainTime=`${m}:${s}`;
if(m==0 && s==0){
//location.reload();//刷线页面
_this.dotaskDis=true;
}
}
timer=setInterval(countDown,1000);
},