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();
        };
  • 相关阅读:
    HTML 拖放 和 地理定位
    HTML web存储
    HTML 语义元素 和 MathML元素
    Docker Swarm
    Docker Machine
    Docker Compose
    Docker 的网络模式
    数据共享与持久化
    镜像和容器的基本操作
    Docker 简介
  • 原文地址:https://www.cnblogs.com/Smiled/p/9111713.html
Copyright © 2011-2022 走看看