简体   繁体   English

倒数计时器无法在Chrome / Safari上正常呈现,但在Firefox上正常

[英]Countdown timer doesn't render right on Chrome/Safari, but OK on Firefox

function countDownRound() {
    if(myRoundTimeRemaining >= 0){
        var secs = myRoundTimeRemaining;
        if(secs < 10)
        {
            secs = "0" + secs;
        }
        $("#countdown").html(':'+secs);
        CountdownTimer = setTimeout(countDownRound, 1000);
        myRoundTimeRemaining--;
    }
    else{
        $("#countdown").html('');
    }
}

The code above does what's expected, on Firefox. 上面的代码在Firefox上做了预期的事情。 Every second a decreasing number is displayed in the "countdown" element. 每秒都会在“倒计时”元素中显示递减的数字。

On Safari and Chrome, the code runs properly, but the on-screen element does not change. 在Safari和Chrome上,代码运行正常,但屏幕上的元素不会更改。 If something else happens (such as resizing the browser window) the elements update properly while. 如果发生其他事情(例如调整浏览器窗口的大小),则元素会在适当时更新。

This looks like some kind of optimization or thread-based problem, but I can't find a solution. 这看起来像某种优化或基于线程的问题,但我找不到解决方案。

Works fine for me too on Chrome, Safari and Firefox. 在Chrome,Safari和Firefox上也适用于我。

Perhaps in this case that you don`t need to use html tags to display your result, text() may work better than html() . 也许在这种情况下,您不需要使用html标签来显示结果, text()可能比html()更好。

Try using 尝试使用

$("#countdown").text(':'+secs);

instead html(). 而是html()。

OBS: Seems that some kids of instability on your operacional system can also affects browser rendering. OBS:似乎你的操作系统上的一些不稳定的孩子也会影响浏览器渲染。 Could someone please confirm or deny this? 有人可以确认或否认这个吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM