美文网首页JavaScript
js活动页面倒计时

js活动页面倒计时

作者: LuckyS007 | 来源:发表于2017-10-14 18:33 被阅读23次
  • 通过后台返回的活动结束时间和当前服务器时间,这两个时间戳来转换成倒计时
    还有活动开始时间(比如距离活动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()
       }

相关文章

网友评论

    本文标题:js活动页面倒计时

    本文链接:https://www.haomeiwen.com/subject/wkrfuxtx.html