Firefox中的Javascript setinterval()滞后吗? [英] Javascript setinterval() lag in Firefox?

查看:121
本文介绍了Firefox中的Javascript setinterval()滞后吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了这段代码,以使秒数(以分秒& centisec为单位)递增.

I have wrote this code to make seconds (with decisec & centisec) counting up.

    You've wasted time <span id="alltime">0.00</span> seconds.

    <script type="text/javascript"> 
    function zeroPad(num,count)
    {
    var numZeropad = num + '';
    while(numZeropad.length < count) { numZeropad = "0" + numZeropad; }
    return numZeropad; }
    function counttwo() {
    tall = document.getElementById('alltime').innerHTML;
    if(parseFloat(tall) < 1.00) {     tnew2 = tall.replace('0.0','').replace('0.','');    }
        else {    tnew2 = tall.replace('.','');    }
    tnum = parseInt(tnew2) + 1;
       //check if have to add zero 
if(tnum >= 100) { tstr1 = tnum + ''; }
        else { tstr1 = zeroPad(tnum,3); }
    tlast = tstr1.substr(0,tstr1.length - 2) + '.' + tstr1.substr(tstr1.length - 2);
        document.getElementById("alltime").innerHTML = tlast;
    }
    var inttwo=setInterval("counttwo()",10);
    </script>

在HTML文档中并运行.

In HTML document and run.

它运行良好,但是当我使用Firefox 4并运行代码时.当它在某个数字上时(有点像12.20、4.43),似乎有点滞后(在计数之前停了一下).我尝试将"counttwo()"更改为counttwo,但这无济于事.

It works well but when I use Firefox 4 and run the code. Seems like it LAG a bit (stop a bit before counting up) when it's on some numbers (randomly like 12.20, 4.43). I've tried change "counttwo()" to counttwo but that doesn't help.

我已经告诉我的一些朋友也可以在Firefox 4上运行.他们说这一点也不落后.这是因为我的电脑造成的吗?还是我的Firefox?还是其他?

I have told some of my friends to run on Firefox 4 too. They said it doesn't lag at all. This cause because of my computer ? or My Firefox ? or something else ?

提前谢谢!

PS.在这里提琴: http://jsfiddle.net/XvkGy/5/镜像:

PS. Fiddle here: http://jsfiddle.net/XvkGy/5/ Mirror: http://bit.ly/hjVtXS

推荐答案

使用setInterval或setTimeout时,由于以下几个原因,时间间隔不正确.它取决于其他运行的Javascript,浏览器,处理器等.您必须为+ a- 15ms的可靠性授予afaik. 请参阅...

When you use setInterval or setTimeout the time interval is not exact for several reasons. It is dependent on other javascript running, the browser, the processor etc. You have to take a reliability of +- 15ms for granted afaik. See also ...

这篇关于Firefox中的Javascript setinterval()滞后吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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