用CSS语言编倒计时表

html-css017

用CSS语言编倒计时表,第1张

css没有这个功能。

要做倒计时表,至少你得用JS或VBS。CSS只是用来控制页面布局、页面风格等。喝在说CSS里也可以控制JS脚本运行,但是实际上还是JS脚本在运行,而并非CSS语言自身的功能。。

而用JS或VBS做一个倒计时表,百度上搜一下,代码太多了。。

用定时器setTimeout('clock()',1000)就行了(其中clock()就是你用来显示时间的自定义funcion。

我简单制作了一个,你看是否是你所需要的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />

<title>无标题文档</title>

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

<style type="text/css">

*{margin:0pxpadding:0px}

.main{border:1px double #cccwidth:300pxheight:100px}

.deng{width:90pxheight:90pxfloat:leftborder:3px solid blackbackground-color:#CCCCCCborder-radius:45pxmargin-left:2px}

.jiShi{margin:5px 10pxcolor:#FF00FF}

</style>

</head>

<body>

<div class="main">

<div class="deng c0"></div>

<div class="deng c1"></div>

<div class="deng c2"></div>

<div class="jiShi">

00:00:30

</div>

<H3>每隔30秒变换一次</H3>

</div>

<script type="text/javascript">

window.onload=function(){

let timer,timer2

let n = 0

let t = 29

let colors = ["red","green","yellow"]

timer = window.setInterval(function(){

if(t==0){

$(".deng").css({"backgroundColor":"#CCC"})

$(".c" + n).css({"backgroundColor":colors[n]})

n++

if(n==3){n=0}

t=30

}else{

$(".jiShi").text("00:00:" + t)

t--

}

},1000)

}

</script>

</body>

</html>