zoukankan      html  css  js  c++  java
  • 倒计时1

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>倒计时案例1</title>
        <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        </style>
    </head>
    
    <body>
        <div><span id="div_countDown"></span>后恢复原价</div>
        <script type="text/javascript">
        //倒计时
        var countDown = {
            flag: true,
            hour: 0,
            minutes: 0,
            minutesNew: 0,
            seconds: 0,
            show: 0,
            current: 0,
            length: 0,
            showTagId: null,
            // callback: null, 
            countDownInner: function(vTimeLength) {
                if (!this.flag) {
                    return;
                }
                var that = this;
                this.current = vTimeLength;
                minutes = Math.floor(vTimeLength / 60);
                seconds = Math.floor(vTimeLength % 60);
                if (minutes >= 60) {
                    hour = Math.floor(minutes / 60);
                    minutesNew = Math.floor(minutes % 60);
                    if (hour < 10) {
                        hour = "0" + hour;
                    }
                    if (minutesNew < 10) {
                        minutesNew = "0" + minutesNew;
                    }
                    if (seconds < 10) {
                        seconds = "0" + seconds;
                    }
                    show = hour + ":" + minutesNew + ":" + seconds;
    
                } else {
                    if (minutes < 10) {
                        minutes = "0" + minutes;
                    }
                    if (seconds < 10) {
                        seconds = "0" + seconds;
                    }
                    show = minutes + ":" + seconds;
                }
                document.getElementById(this.showTagId).innerHTML = show;
                vTimeLength = vTimeLength - 1;
                if (vTimeLength > 0) {
                    setTimeout(function() { that.countDownInner(vTimeLength); }, 1000);
                } else {
                    setTimeout(function() { that.callback(); }, 1000);
                }
            },
            run: function(vTimeLength, showTagId, callback) {
                if (!this.flag) {
                    this.flag = true;
                    this.countDownInner(this.current);
                } else if (showTagId) {
                    this.length = vTimeLength;
                    this.showTagId = showTagId;
                    this.callback = callback;
                    this.countDownInner(vTimeLength);
                }
            }
    
        };
        //参数 1.倒计时的秒数   2.控件的id    3.时间到了执行的方法
        countDown.run(7200, 'div_countDown', function() { document.getElementById('div_countDown').innerHTML = '结束' });
        </script>
    </body>
    
    </html>

    效果图:

  • 相关阅读:
    element-ui upload 上传图片之前压缩
    字符串截取substring放法传参不同返回不同
    vue中对于图片是否正常加载的思考
    前端图片合成并下载
    vue中图相对路径引用本地图片
    js计算精度
    vue-cli定义全局过滤器
    js加减乘除运算丢失精度 前端计算金额带小数点精度丢失问题
    鼠标样式大全
    js两小时倒计时,剩余时间倒计时,倒计时
  • 原文地址:https://www.cnblogs.com/huanghuali/p/8430772.html
Copyright © 2011-2022 走看看