JS加HTML加CSS怎么制作红绿灯倒计时?

JS加HTML加CSS怎么制作红绿灯倒计时?,第1张

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

<!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>

不用太复杂,基础学的我想就应该可以作,使用select case 进行选择就可以了,再作两张底图,一张为红色,一张为绿色,将两张图叠在一起隐藏,通过change来判断显示哪一张我想就可以了。 在窗体内加入两个label,其中label1.caption=6(作为倒计时数),添加一个timer,设定interval=1000,添加一个按键作为开始,添加两个picture,把背景分别设为红色与绿色,设置两个picture的Visible都为false,然后代码如下:

Private Sub Command1_Click()

Timer1.Enabled = True'时间开启

End Sub

Private Sub Form_Load()

Timer1.Enabled = False'时间关闭

End Sub

Private Sub Label1_Change()

If Label1.Caption = 0 Then'如果label1=0那么返回6

Label1.Caption = 6

End If

Select Case Label1.Caption

Case 3'判断label1=3时,显示红色

Picture1.Visible = False

Picture2.Visible = True

Case 1判断label1=1时,显示绿色

Picture2.Visible = False

Picture1.Visible = True

End Select

End Sub

Private Sub Label2_Change()

Label1.Caption = Label1.Caption - 1'当label2发生变化时,label1-1

End Sub

Private Sub Timer1_Timer()

If Label2.Caption <>Str(Timer) Then'将时间附值给label2

Label2.Caption = Time

End If

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7059276.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-01
下一篇 2023-04-01

发表评论

登录后才能评论

评论列表(0条)

保存