Js倒计时代码精确到毫秒。
/***倒计时***///varoverDate=1000*60*60*24*3;//截止时间:为当前计算机时间+3天varNowTime=newDate();varEn...
/***倒计时***/
//var overDate = 1000 * 60 * 60 * 24 * 3; //截止时间:为当前计算机时间+3天
var NowTime = new Date();
var EndTime= new Date(2013,10,12,0,0); //截止时间:为固定时间
//var EndTime = new Date(NowTime.getTime() + overDate);
var EndTimeMsg = EndTime.getFullYear() + "年";
EndTimeMsg = EndTimeMsg + (EndTime.getMonth() + 1) + "月";
EndTimeMsg = EndTimeMsg + (EndTime.getDate()) + "日";
EndTimeMsg = EndTimeMsg + (EndTime.getHours()) + "时";
EndTimeMsg = EndTimeMsg + (EndTime.getMinutes()) + "分";
EndTimeMsg = EndTimeMsg + (EndTime.getSeconds()) + "秒";
function GetRTime()
{
NowTime = new Date();
var nMS = EndTime.getTime() - NowTime.getTime();
var nD = Math.floor(nMS / (1000 * 60 * 60 * 24));
var nH = Math.floor(nMS / (1000 * 60 * 60)) % 24;
var nM = Math.floor(nMS / (1000 * 60)) % 60;
var nS = Math.floor(nMS / 1000) % 60;
var nSS = Math.floor(nMS /100) % 10;
if (nD >= 0)
{
if(nD<10){ nD = "0" + nD; }
if(nH<10){ nH = "0" + nH; }
if(nM<10){ nM = "0" + nM; }
if(nS<10){ nS = "0" + nS; }
if(nSS<10){nSS="0"+ nSS; }
document.getElementById("RemainH").innerHTML = nH;
document.getElementById("RemainM").innerHTML = nM;
document.getElementById("RemainS").innerHTML = nS ;
document.getElementById("RemainSS").innerHTML = nSS ;
}
else {
document.getElementById("CountMsg").innerHTML = EndTimeMsg + "已过期!";
}
setTimeout("GetRTime()", 100);
}
window.onload = function() {
GetRTime();
}
</script>
如何让毫秒更快一些,例如1秒钟转50毫秒。 展开
//var overDate = 1000 * 60 * 60 * 24 * 3; //截止时间:为当前计算机时间+3天
var NowTime = new Date();
var EndTime= new Date(2013,10,12,0,0); //截止时间:为固定时间
//var EndTime = new Date(NowTime.getTime() + overDate);
var EndTimeMsg = EndTime.getFullYear() + "年";
EndTimeMsg = EndTimeMsg + (EndTime.getMonth() + 1) + "月";
EndTimeMsg = EndTimeMsg + (EndTime.getDate()) + "日";
EndTimeMsg = EndTimeMsg + (EndTime.getHours()) + "时";
EndTimeMsg = EndTimeMsg + (EndTime.getMinutes()) + "分";
EndTimeMsg = EndTimeMsg + (EndTime.getSeconds()) + "秒";
function GetRTime()
{
NowTime = new Date();
var nMS = EndTime.getTime() - NowTime.getTime();
var nD = Math.floor(nMS / (1000 * 60 * 60 * 24));
var nH = Math.floor(nMS / (1000 * 60 * 60)) % 24;
var nM = Math.floor(nMS / (1000 * 60)) % 60;
var nS = Math.floor(nMS / 1000) % 60;
var nSS = Math.floor(nMS /100) % 10;
if (nD >= 0)
{
if(nD<10){ nD = "0" + nD; }
if(nH<10){ nH = "0" + nH; }
if(nM<10){ nM = "0" + nM; }
if(nS<10){ nS = "0" + nS; }
if(nSS<10){nSS="0"+ nSS; }
document.getElementById("RemainH").innerHTML = nH;
document.getElementById("RemainM").innerHTML = nM;
document.getElementById("RemainS").innerHTML = nS ;
document.getElementById("RemainSS").innerHTML = nSS ;
}
else {
document.getElementById("CountMsg").innerHTML = EndTimeMsg + "已过期!";
}
setTimeout("GetRTime()", 100);
}
window.onload = function() {
GetRTime();
}
</script>
如何让毫秒更快一些,例如1秒钟转50毫秒。 展开
2个回答
展开全部
setTimeout("GetRTime()", 100); 改为setTimeout("GetRTime()", 20); 就是≈50毫秒了,1s = 1000ms,1000 ÷ 50 = 20,然后由于javascript的单线程方式,setTimeout并不一定会在20ms时执行,所以只能说≈了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询