zoukankan      html  css  js  c++  java
  • js实现活动倒计时

          let startTime = 1527647143949; // 开始时间
            var time = new Countdown('timer',startTime);
              function Countdown (el,startTime) {
                this.startTime = startTime || '';
                this.el = el || '';
                // 轮询计算时间
                this.loop = function () {
                var that = this;
              setInterval(function(){
                that.init();
                },1000);
              };
            // 格式化时分秒
            this.formatDuring = function (mss) {
              var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
              var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
              var seconds = parseInt((mss % (1000 * 60)) / 1000);
                return hours + ": " + (minutes < 10 ? '0'+minutes : minutes) + ": " + (seconds < 10 ? '0'+seconds : seconds);
              };
            // 初始化倒计时
            this.init = function () {
              var endTime = this.startTime+(24*60*60*1000); // 结束时间
              var timeLeft = endTime - new Date().getTime(); // 剩余时间
                document.getElementById(this.el).innerHTML = this.formatDuring(timeLeft);
                this.loop();
                  };
                this.init();
                };

  • 相关阅读:
    从B树、B+树、B*树谈到R 树
    The Log-Structured Merge-Tree(译)
    Leveldb源码分析--2
    Leveldb源码分析--1
    little-endian And big-endian
    Fixed数据类型
    Varint数值压缩存储方法
    JavaEE开发之SpringBoot工程的创建、运行与配置
    Javaee基本框架(Struts2,Spring,MyBatista)之间的关系
    XLM解析技术概述
  • 原文地址:https://www.cnblogs.com/wgy0528/p/9444024.html
Copyright © 2011-2022 走看看