zoukankan      html  css  js  c++  java
  • 商城倒计时,按照当前时间和次日凌晨算时间

    1.公用的方法:

    // 倒计时
    /*
    参数:
        hourTime:还剩多少毫秒;
        hourDom:需要展示小时数的dom;
        minuDom:需要展示分钟的dom;
        secDom:需要展示秒数的dom;
        callback:回调函数;
    */
     function returnTimer(hourTime,hourDom, minuDom, secDom, callback) {
            var maxtime = hourTime / 1000; //按秒计算,自己调整! 
            CountDown();
            function CountDown() {
                if (maxtime >= 0) {
                    if(hourDom){//有的倒计时可以不展示小时数,就把hourDom传值false;
                        var hours =  Math.floor(Math.floor(maxtime / 60) / 60);
                        if (hours < 10) {
                            hourDom.text(0 + '' + hours);
                        } else {
                            hourDom.text(hours);
                        };
                    }
                    var minutes =  Math.floor(Math.floor(maxtime / 60) % 60);
                    var seconds = Math.floor(maxtime % 60);
                   
                    
                    if (minutes < 10) {
                        minuDom.text(0 + '' + minutes);
                    } else {
                        minuDom.text(minutes);
                    };
                    if (seconds < 10) {
                        secDom.text(0 + '' + seconds);
                    } else {
                        secDom.text(seconds);
                    };
                    // if (maxtime == 5 * 60) alert("还剩5分钟");
                    --maxtime;
                    setTimeout(CountDown, 1000);
                } else {
                    callback();
                    if(hourDom){
                        hourDom.text("00");
                    }
                    minuDom.text("00");
                    secDom.text("00");
                }
            };
        };        

    2.计算剩余时间

    //倒计时
        function animateTime(){
          var endDay =new Date(); //endDay 结束时间
          endDay.setDate(new Date().getDate() + 1) ;
          endDay.setHours(0);
          endDay.setMinutes(0);
          endDay.setSeconds(0);
          var startTime = new Date(); //开始时间是现在
          var remainTime = endDay - startTime;
          returnTimer(remainTime, $(".ld-fb-time.minutes"), $(".ld-fb-time.seconds"), function(){},$(".ld-fb-time.hours"))
        }
        animateTime()
  • 相关阅读:
    SolrQuery的使用
    solr服务(搜索服务)
    linux下安装jdk
    Gartner:2018人工智能技术成熟度曲线
    Gartner 2018新技术成熟度曲线
    Market Guide for AIOps Platforms
    OpenStack的基本概念与架构图
    OpenStack OVS GRE/VXLAN
    VLAN,GRE,VXLAN
    企鹅智库发布《2019-2020中国互联网趋势报告》
  • 原文地址:https://www.cnblogs.com/chun321/p/10696098.html
Copyright © 2011-2022 走看看