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();
  • 相关阅读:
    C# 泛型
    EventHandler<TEventArgs>委托
    只能输入数字 ,只能有一位小数点。
    MVC过滤器 AuthorizeAttribute使用
    NuGet EntityFramework 常用命令
    Stride游戏引擎试毒
    Unity EditorWindow GUI裁剪
    unity2017自定义编译dll
    Unity
    WPF
  • 原文地址:https://www.cnblogs.com/jiangtuzi/p/4301699.html
Copyright © 2011-2022 走看看