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

    function countdown(){
        var countdown = $(".header .time"),
            reduceDay = countdown.children(".countdown"),
            seed = 0,
            startTime = (+new Date(2015,1,13,18,0,0,0)) / 1000;
        function numFormat(num){
            if(num < 10){
                return "0" + num;
            }else{
                return num;
            }
        }
        function timeEnd(){
            reduceDay.text("00");
        }
        function setRemainTime(time){
            time = time - seed;
            if (time > 0) {
                var day = Math.floor((time / 3600) / 24);
                reduceDay.text(numFormat(day));
            } else {
                timeEnd();
            }
            seed++;
        }
        function ajaxHandle(xhr){
            var headers = xhr.getResponseHeader('Date'),
                tmp = Date.parse(headers) / 1000,
                reduce = startTime - tmp;
            if(reduce > 0) {
                countdown.attr('diff','');
                countdown.attr('diff', reduce);
                var time = parseInt(countdown.attr('diff'));
                setRemainTime(time);
                var InterValObj = window.setInterval(function(){setRemainTime(time)},1000);
            }
            else{
                timeEnd();
            }
        }
        $.ajax({
            type : "get",
            url : "http://ltt.1905.com/time.html",
            cache : false,
            success : function(data,status,xhr){
                ajaxHandle(xhr);
            },
            error : function(xhr){
                ajaxHandle(xhr);
            }
        });
    }
    countdown();
  • 相关阅读:
    MySQL 存储过程和函数02
    MySQL 视图 存储过程(未完)
    MySQL 简单索引
    Nginx 设置前后端跨域
    Pipeline流水线 自动脚本
    luogu 2024 食物链
    spoj Corporative Network
    luogu2787 语文1(chin1)- 理理思维
    HDU6579 Operation
    luogu3857 彩灯
  • 原文地址:https://www.cnblogs.com/jiangtuzi/p/4301699.html
Copyright © 2011-2022 走看看