惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
GbyAI
GbyAI
博客园 - 司徒正美
美团技术团队
Vercel News
Vercel News
IT之家
IT之家
U
Unit 42
Y
Y Combinator Blog
罗磊的独立博客
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
V
Visual Studio Blog
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MyScale Blog
MyScale Blog
博客园 - 叶小钗
A
About on SuperTechFans
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
B
Blog RSS Feed

博客园 - s80895304

win8 framework3.5安装 ChangeCharToTable sql 触发器 mysql 备忘sql ActiveMQ 安装 【转】j2ee 环境搭建 C#原始类型扩展方法—this参数修饰符 消息队列(Message Queue)简介及其使用 IE中同一个url第二次AJAX调用无法触发onreadystatechange事件 Web Service 身份验证 sql 索引 Memcached、MongoDB、Redis和tokyotyrant 【转】ActiveMQ redis iphone 技巧 10款iOS高效开发必备的Objective-C类库 ASIHTTPRequest Queue 队列 写日志简单应用 js keycode
jquery 倒计时插件
s80895304 · 2011-10-14 · via 博客园 - s80895304

 <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script>
        (function ($) {
            var countdown = function (item, config) {
                var st = new Date(parseInt($(item).attr(config.st)) * 100);
                var et = new Date(parseInt($(item).attr(config.et)) * 100);
                //alert(st.toLocaleString());
                //alert(et.toLocaleString());
                //var seconds = parseInt($(item).attr(config.attribute));
                var seconds = ((et - st) / 1000).toString();
                var timer = null;

                var doWork = function () {
                    if (seconds >= 0) {
                        if (typeof (config.callback) == "function") {
                            var data = {
                                total: seconds,
                                second: Math.floor(seconds % 60),
                                minute: Math.floor((seconds / 60) % 60),
                                hour: Math.floor((seconds / 3600) % 24),
                                day: Math.floor(seconds / 86400)
                            };
                            config.callback.call(item, seconds, data, item);
                        }
                        seconds--;
                    } else {
                        window.clearInterval(timer);
                    }
                }
                timer = window.setInterval(doWork, 1000);
                doWork();
            };
            var main = function () {
                var args = arguments;
                var config = { attribute: 'data-seconds', st: 'st', et: 'et', callback: null };
                if (args.length == 1) {
                    if (typeof (args[0]) == "function") config.callback = args[0];
                    if (typeof (args[0]) == "object") $.extend(config, args[0]);
                } else {
                    config.attribute = args[0];
                    config.callback = args[1];
                }
                $(this).each(function (index, item) {
                    countdown.call(function () { }, item, config);
                });
            };
            $.fn.countdown = main;
        })(jQuery);

    </script>
    <script type="text/javascript">
        $(function () {
            //alert(new Date('2011-10-15').getDay());
            //countdown({ attribute: 'data', callback: function () { }, });
            $('ul').countdown(function (s, d) {
                var items = $(this).find('span');
                items.eq(3).text(d.second);
                items.eq(2).text(d.minute);
                items.eq(1).text(d.hour);
                items.eq(0).text(d.day);
            });
        });
    </script>

<ul data-seconds="10" st="13187455380" et="13187455700">
        <li><span>-</span>天</li>
        <li><span>-</span>时</li>
        <li><span>-</span>分</li>
        <li><span>-</span>秒</li>
    </ul>
    <ul data-seconds="20" st="13187455380" et="13187455790">
        <li><span>-</span>天</li>
        <li><span>-</span>时</li>
        <li><span>-</span>分</li>
        <li><span>-</span>秒</li>
    </ul>
    <ul data-seconds="30" st="13187455380" et="13187455910">
        <li><span>-</span>天</li>
        <li><span>-</span>时</li>
        <li><span>-</span>分</li>
        <li><span>-</span>秒</li>
    </ul>
===========================================================================

var timer;
function TimeDown(id, endDateStr, interval) {
var endDate = new Date(endDateStr);
var nowDate = new Date();
if (endDate <= nowDate) { clearTimeout(timer); return; }
var totalSeconds = parseInt((endDate - nowDate) / 1000);
var days = Math.floor(totalSeconds / (60 * 60 * 24));
var modulo = totalSeconds % (60 * 60 * 24);
var hours = Math.floor(modulo / (60 * 60));
modulo = modulo % (60 * 60);
var minutes = Math.floor(modulo / 60);
var seconds = modulo % 60;

//sb.Append("<span class=\"s1\">0</span> <span class=\"s1\">6</span> <span class=\"s2\">天</span> <span class=\"s1\">2</span> <span class=\"s1\">3</span> <span class=\"s2\">小时</span> <span class=\"s1\">5</span> <span class=\"s1\">9</span> <span class=\"s2\">分</span>");

document.getElementById(id).innerHTML = "还剩:" + days + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒"; //延迟一秒执行自己
var timer = setTimeout(function () { TimeDown(id, endDateStr); }, interval)
}
TimeDown("timer", '2014-11-11', 1000);