倒计时html代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了倒计时html代码相关的知识,希望对你有一定的参考价值。
倒计时在每天8点开始24个小时的倒计时,要和本地时间同步,谢谢了!
倒计时的html代码:
<!DOCTYPE HTML><html>
<head>
<meta charset="utf-8">
<title>CSS3圆环倒计时-源码搜藏网</title>
<style>
.pie width:200px; height:200px; background-color:blue; border-radius:100px; position:absolute;
.pie1 clip:rect(0px,200px,200px,100px); -o-transform:rotate(0deg); -moz-transform:rotate(0deg); -webkit-transform:rotate(0deg); background:-moz-radial-gradient(20% 50% 0deg, #333, #0000ff); background:-webkit-gradient(radial, 100 100, 0, 100 100, 110, from(#000), to(#0000ff));
.pie2 clip:rect(0px,100px,200px,0px); -o-transform:rotate(0deg); -moz-transform:rotate(0deg); -webkit-transform:rotate(0deg); background:-moz-radial-gradient(80% 50% 0deg, #333, #0000ff); background:-webkit-gradient(radial, 100 100, 0, 100 100, 110, from(#000), to(#0000ff));
.hold width:200px; height:200px; position:absolute; z-index:1;
.hold1 clip:rect(0px,200px,200px,100px);
.hold2 clip:rect(0px,100px,200px,0px);
.bg width:200px; height:200px; background-color:red; border-radius:100px; position:absolute; box-shadow:0px 0px 8px #333; background:-moz-radial-gradient(0% 50% 0deg, #900, #ff0000); background:-webkit-gradient(radial, 100 100, 0, 100 100, 110, from(#900), to(#ff0000));
.time width:160px; height:160px; margin:20px 0 0 20px; background-color:#fff; border-radius:100px; position:absolute; z-index:1; box-shadow:0px 0px 8px #333 inset; text-align:center; line-height:160px; font-family:"Book Antiqua", Palatino, serif; font-size:35px; font-weight:bold; text-shadow: 1px 1px 3px #333;
.time em background:#fff; position:absolute; top:62px; left:12px; height:18px; width:140px; opacity:0.4;
</style>
</head>
<body>
<div class="hold hold1">
<div class="pie pie1"></div>
</div>
<div class="hold hold2">
<div class="pie pie2"></div>
</div>
<div class="bg"> </div>
<div class="time"><span></span><em></em></div>
<script src="http://www.codefans.net/ajaxjs/jquery-1.6.2.min.js"></script>
<script>
i = 0;
j = 0;
count = 0;
MM = 4;
SS = 59;
MS = 9;
totle = (MM+1)*600;
d = 180*(MM+1);
MM = "0" + MM;
function showTime()
totle = totle - 1;
if(totle==0)
clearInterval(s);
clearInterval(t1);
clearInterval(t2);
$(".pie2").css("-o-transform","rotate(" + d + "deg)");
$(".pie2").css("-moz-transform","rotate(" + d + "deg)");
$(".pie2").css("-webkit-transform","rotate(" + d + "deg)");
else
if(totle>0 && MS>0)
MS = MS - 1;
if(MS < 10)MS = "0" + MS;
;
if(MS==0 && SS>0)
MS = 10;
SS = SS - 1;
if(SS < 10)SS = "0" + SS;
;
if(SS==0 && MM>0)
SS = 60;
MM = MM - 1;
if(MM < 10)MM = "0" + MM;
;
;
$(".time span").html(MM + ":" + SS + ":" + MS);
;
s = setInterval("showTime()",100);
function start1()
i = i + 0.6;
count = count + 1;
if(count==300)
count = 0;
clearInterval(t1);
t2 = setInterval("start2()",100);
;
$(".pie1").css("-o-transform","rotate(" + i + "deg)");
$(".pie1").css("-moz-transform","rotate(" + i + "deg)");
$(".pie1").css("-webkit-transform","rotate(" + i + "deg)");
;
function start2()
j = j + 0.6;
count = count + 1;
if(count==300)
count = 0;
clearInterval(t2);
t1 = setInterval("start1()",100);
;
$(".pie2").css("-o-transform","rotate(" + j + "deg)");
$(".pie2").css("-moz-transform","rotate(" + j + "deg)");
$(".pie2").css("-webkit-transform","rotate(" + j + "deg)");
;
t1 = setInterval("start1()",100);
</script>
<input onclick="window.open(\'view-source:\' + window.location.href)" type="button" value="查看源代码" style="position:absolute; right:0; top:0; width:80px; height:30px;">
</body>
</html>
直接复制代码,创建html文件,然后复制进去,就可以看到效果了。
刚写的例子:
<!doctype html><html>
<head>
<meta charset="utf-8">
<title>倒计时</title>
</head>
<script>
window.onload = function()
var iTotalTime = 23 + 8;//每天8点距离第二天8的时间
var oHour = document.getElementById("hour");
var oMin = document.getElementById("min");
var oSen = document.getElementById("sen");
var iDin = 59;
//一秒执行一次
setInterval(function()
var dDate = new Date();//获得本地时间
var getMin = 59 - dDate.getMinutes();
var getSen = 59 - dDate.getSeconds();
oHour.innerHTML = iTotalTime - dDate.getHours();
oMin.innerHTML = getMin > 9 ?getMin:"0"+getMin;
oSen.innerHTML = getSen > 9 ?getSen:"0"+getSen;
,1000);
</script>
<body>
<div>
本场剩余:<span id="hour">00</span>时<span id="min">00</span>分<span id="sen">00</span>秒
</div>
</body>
</html>
使用setTimeout()实现倒计时效果代码实例
使用setTimeout()实现倒计时效果代码实例:
大多数情况下实现倒计时效果是使用setInterval()函数,因为此函数可以每隔指定的实现就执行一次指定函数,而setTimeout()函数只能够执行一次,不过也是可以实现倒计时效果的,下面就通过代码实例介绍一下如何利用setTimeout()函数实现倒计时效果。
代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>蚂蚁部落</title> <script type="text/javascript"> function timer() { var value=Number(document.all[‘timer‘].value); if(value>1) { document.all[‘timer‘].value=value-1; } else { document.all[‘timer‘].value="同意"; return false; } window.setTimeout("timer()",1000); } window.onload=function(){timer()} </script> </head> <body> <input name="timer" value="10" type="button"/> </body> </html>
以上代码实现了我们的要求,可以使用setTimeout()函数实现倒计时效果,尽管setTimeout()只能够执行一次,但是可以使用递归的方式,不断的调用自身,就可以实现倒计时效果,具体实现过程这里就多介绍了,可以参阅相关阅读。
相关阅读:
1.Number()函数可以参阅javascript的Number()方法一章节。
2.setTimeout()函数可以参阅window对象的setTimeout()方法一章节。
3.document.all可以参阅javascript的document.all的用法一章节。
原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=11519
更多内容可以参阅:http://www.softwhy.com/javascript/
以上是关于倒计时html代码的主要内容,如果未能解决你的问题,请参考以下文章