zoukankan      html  css  js  c++  java
  • 做一个倒计时的功能,天,时,分 /时,分,秒

    如果有天的存在,就是天,时,分,如果没有天的存在,就是时,分,秒

    <p class="fishqcTryProduct-value" style="margin-top: .5rem">据开抢:
         <span class="fishqc-padding" ms-visible="el.days!='0'||el.days0!='0'"><span>{{el.days0}}</span><span>{{el.days}}</span></span><span ms-visible="el.days!='0'||el.days0!='0'">天</span>
         <span class="fishqc-padding"><span>{{el.hours1}}</span><span>{{el.hours2}}</span></span><span class="fishqc-padding"><span>{{el.minutes1}}</span><span>{{el.minutes2}}</span></span><span class="fishqc-padding" ms-visible="el.days=='0'&&el.days0=='0'"><span>{{el.seconds1}}</span><span>{{el.seconds2}}</span></span><span ms-visible="el.days=='0'&&el.days0=='0'">秒</span>
    </p>

    下面是js代码:

     setInterval(function() {
          vmi.tryGoodspRreviewList.forEach(function(val, index) {
              val.startleft--;
              var gettime = vmi.daojishiHandle(val.startleft);
              val.days0 = gettime.days0
              val.days = gettime.days
              val.hours1 = gettime.hours1;
              val.hours2 = gettime.hours2;
              val.minutes1 = gettime.minutes1;
              val.minutes2 = gettime.minutes2;
              val.seconds1 = gettime.seconds1;
              val.seconds2 = gettime.seconds2;
             })
    },
    1000)
     daojishiHandle:function(val) {
            var allday = parseInt(val / 24 / 60 / 60)
    
            var time = val % (24 * 3600)
            var hour = parseInt(time / 60 / 60);
            var minutes = parseInt(time / 60 - hour * 60);
            var seconds = time - hour * 60 * 60 - minutes * 60;
    
            var day2 = parseInt(allday / 10)
            var day1 = allday % 10
    
            var hour0 = parseInt(hour / 10);
            var hour1 = hour % 10;
    
            var minute0 = parseInt(minutes / 10);
            var minute1 = minutes % 10;
    
            var second0 = parseInt(seconds / 10);
            var second1 = seconds % 10;
    
            return { days0: day2, days: day1, hours1: hour0, hours2: hour1, minutes1: minute0, minutes2: minute1, seconds1: second0, seconds2: second1 }
        },

    这个倒计时花了很多时间,请笑纳,如果有更好的,更简单的正确代码,欢迎分享~~~~

  • 相关阅读:
    常用HTTP Contenttype头信息及文件类型对照
    Web开发专用IDE:Aptana Studio 3.0
    如果张柏芝的孩子长大
    Apache日志分析工具Awstats的安装和配置
    台北貢寮~三貂角燈塔
    [转]ASP,PHP,JSP,ASP.NET 比较
    联想 Thinkpad SL410使用体验
    2011年6月TIOBE编程语言走势图及指数
    百度搜索能力越来越差了,看下图
    PHP 5.3.x中弃用的特性 Deprecated
  • 原文地址:https://www.cnblogs.com/antyhouse/p/8491801.html
Copyright © 2011-2022 走看看