JQuery倒计时计时器延迟 [英] JQuery countdown timer delayed

查看:128
本文介绍了JQuery倒计时计时器延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了JQuery Countdown Timer(jquery.lwtCountdown-1.0.js)。在不同的机器和相同的机器不同的浏览器中,我面临计时器的延迟。有时总共15分钟需要40-50秒延迟。 javascript逻辑定义如下:

I have implemented the JQuery Countdown Timer (jquery.lwtCountdown-1.0.js). Am facing the delay in the timer in different machines and same machine different browsers. Sometimes it take 40-50 seconds delay in total 15 mins. The javascript logic is defined below:

<script type="text/javascript" >
    var Timer;

    function CreateTimer(TimerID, Time){
            Timer = document.getElementById(TimerID);
    TotalSeconds = Time;

    UpdateTimer();
    window.setTimeout("Tick()", 1000);
}
function Tick() {
    TotalSeconds -= 1;
    if(TotalSeconds>=0){
        UpdateTimer();
        window.setTimeout("Tick()", 1000);
    }else{
            // NO TIME THEN LOGOUT
                    //          alert(SUCCESS_LOGOUT);
    }
}
function UpdateTimer() {
        var Seconds = TotalSeconds;

    var Days = Math.floor(Seconds / 86400);
    Seconds -= Days * 86400;

    var Hours = Math.floor(Seconds / 3600);
    Seconds -= Hours * (3600);

    var Minutes = Math.floor(Seconds / 60);
    Seconds -= Minutes * (60);


    var TimeStr = "" +((Days > 0) ? Days + " days " : "") + LeadingZero(Hours) + ":" + LeadingZero(Minutes) + ":" + LeadingZero(Seconds)+"<b>"
    Timer.innerHTML = TimeStr;
}

function LeadingZero(Time) {
    return (Time < 10) ? "0" + Time : + Time;
}

</script>

以上代码是javascript的。我找不到任何计时器延迟的解决方案。
是否有任何遗漏?

This above code is of javascript. I can't find any resolution for timer getting delayed. Is there anything am missing?

预先感谢!!!

推荐答案

您的代码有两个问题:

There is two issues with your code:

1. window.setTimeout("Tick()", 1000); here you are passing a string you need to 
                                      pass  a function 
2. you need a global variable for TotalSeconds

我不确定这段代码是干什么的,但是这里有一个正在工作的 DEMO < a>

i'm not sure what this code does, however here is a working DEMO

这篇关于JQuery倒计时计时器延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆