jQuery 1 minute countdown with milliseconds and callback

最后都变了- 提交于 2019-12-01 10:56:36

问题


I'm trying to figure out a way to display a simple countdown that displays 1:00:00 whereby 1 = minutes, 00 = seconds, and 00 = milliseconds.

I've found loads of jQuery countdowns on the interwebs, but none of the contain the ability to display milliseconds natively, and I really don't want to dig through thousands of lines of code to try and find a way to hack it in there myself.

Is this something that would be pretty easy to whip up?

I'm also hoping to have the ability to add a callback to the end of the countdown (0:00:00) so that when it finishes, I can run another function.


回答1:


This is going to sound a bit off the cuff, but if you make a small animated GIF that runs through ten random sets of two digits ten times a second, your users will never know the difference, and you won't have to worry about what you're going to do to your CPU load by trying to count down milliseconds in a web page.




回答2:


Hi guys I have developed a code for my self use the following code counter for 20 seconds

var _STOP =0;

var value=1999;

function settimer()

{
var svalue = value.toString();

if(svalue.length  == 3)

    svalue = '0'+svalue;
else if(svalue.length  == 2)
    svalue = '00'+svalue;
else if(svalue.length  == 1)
    svalue = '000'+svalue;
else if(value == 0)
    svalue = '0000';
document.getElementById('cn1').innerHTML = svalue[0];
document.getElementById('cn2').innerHTML = svalue[1];
document.getElementById('cn3').innerHTML = svalue[2];
document.getElementById('cn4').innerHTML = svalue[3];   
value--;

if (_STOP==0 && value>=0) setTimeout("settimer();", 10);
}

setTimeout("settimer()", 10);


来源:https://stackoverflow.com/questions/3020062/jquery-1-minute-countdown-with-milliseconds-and-callback

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!