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

    (function ($) {
        jQuery.fn.extend({
            countDown: function (opts) {
                opts = jQuery.extend({
                    endDate: "2013/11/11 9:12",//最后时间
                    cssClass: "imgDiv",
                    message: "",
                    miniteToAlert: 5,
                    callback: function () { return false; }
                }, opts || {});
                var $this = $(this);
                $this.addClass(opts.cssClass);
                //计时功能
                var totalSecs, days, hours, mins, secs, date;
                var date1 = new Date(opts.endDate);
                var flag = true;
    
                var timer = setInterval(function () {
                    date = new Date();
                    if (date1- date  >= 0) {
                        totalSecs = (date1-date  ) / 1000;
                        days = Math.floor(totalSecs / 3600 / 24);
                        hours = Math.floor((totalSecs - days * 24 * 3600) / 3600);
                        mins = Math.floor((totalSecs - days * 24 * 3600 - hours * 3600) / 60);
                        secs = Math.floor((totalSecs - days * 24 * 3600 - hours * 3600 - mins * 60));
                        if (flag && mins < opts.miniteToAlert && days == 0 && hours == 0) {
                            alert(opts.message);
                            flag = false;
                        }
                        if (days < 10)
                            days = "0" + days;
                        if (hours < 10)
                            hours = "0" + hours;
                        if (mins < 10)
                            mins = "0" + mins;
                        if (secs < 10)
                            secs = "0" + secs;
                        $this.html("");
                        $this.append(days + " " + hours + " " + mins + " " + secs);
                    } else {
                        $this.html("");
                        $this.append("00 00 00 00");
                        opts.callback();
                        clearInterval(timer);
                    }
                }, 1000);
            }
        });
    })(jQuery);
  • 相关阅读:
    又是运行不到main的问题
    stlink问题
    AD7124踩过的坑
    stm32上调试AD5410
    linux读xml文件问题
    stm8问题记录
    430 仿真器 问题
    虚拟机VMware显示“内部错误”的解决方法
    VS2008 如何设置字体大小?
    Hyperledger Indy项目
  • 原文地址:https://www.cnblogs.com/rlm0909/p/3422580.html
Copyright © 2011-2022 走看看