• js 倒计时


    /**
     * 倒计时
     * 前提条件:在对象上需要自定义属性 data-now/data-end
     * 分别表示当前时间秒数以及结束时间秒数
     * 
     * demo1: 
     *  $('.countdown').each(function () {
     *      var my = $(this);
     *      countDown(my);
     *  });
     *
     * demo2: 
     *  $('.countdown').each(function () {
     *      var my = $(this);
     *      countDown(my, function () {
     *          console.log(1);
     *      });
     *  });
     */
    
    function countDown (obj, func) {
        var nowTime = obj.data('now'),
            endTime = obj.data('end'),
            timerFn;
    
        var nD, nH, nM, nS, outStr, times;
    
        function dodo() {
            times = (endTime - nowTime) * 1000;            //时间差
    
            if (times > 0) {
                nD = Math.floor(times / (1000 * 60 * 60 * 24));
                nH = Math.floor(times / (1000 * 60 * 60)) % 24;
                nM = Math.floor(times / (1000 * 60)) % 60;
                nS = Math.floor(times / 1000) % 60;
                if (func) {
                    outStr = func(nD, nH, nM, nS);
                } else {
                    outStr = '<span class="icon_time"></span><span class="brand-days"><em>' + nD 
                            + '</em><i></i></span>' 
                            + '<span class="brand-hours"><em>' + nH + '</em><i></i></span>'
                            + '<span class="brand-minutes"><em>' +nM + '</em><i></i></span>'
                            + '<span class="brand-seconds"><em>' + nS + '</em><i></i></span>';
                }
            } else {
                clearInterval(timerFn);
            }
            obj.html(outStr);
            nowTime++;
        }
    
        dodo();
        timerFn = setInterval(dodo, 1000);
    }

    高否?富否?帅否? 否? 滚去学习!
  • 相关阅读:
    mongodb将mysql数据导入
    mongodb增删改查操作
    mongdb安装
    Python获取两个文件的交集、并集、差集
    java回调函数详解
    java线程锁之synchronized
    mysql知识点汇集
    Springboot2.0实现URL拦截
    idea将springboot打包成jar或者war
    leetcode1128
  • 原文地址:https://www.cnblogs.com/baixc/p/4560865.html
Copyright © 2020-2023  润新知