当前位置:网站首页>JS make a traffic light
JS make a traffic light
2022-07-27 07:25:00 【Ape code takes the lead】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
*{
margin: 0;
padding: 0;
}
main{
background-color: black;
width: 100%;
height: 700px;
}
main div{
width: 250px;
height: 250px;
background-color: darkgrey;
float: left;
margin: 10% 100px;
border-radius: 50%;
color: white;
text-align: center;
line-height: 250px;
font-size: 40px;
}
span{
color: white;
}
span:hover{
cursor: pointer;
}
</style>
<body>
<main>
<div class="red" id="red" > red </div>
<div class="green" id="green"> green </div>
<div class="yellow" id="yellow"> yellow </div>
<span onclick="login()"> Start </span>
</main>
</body>
<script>
let i =2;
let j =2;
let k =3;
let interval;
function login(){
interval = setInterval(demo1,1000);
}
function demo1(){
document.getElementById("red").style = "background-color:red";
document.getElementById("red").innerHTML = i;
if(i==0){
clear1();
demo2();
interval = setInterval(demo2,1000);
return;
}
i--;
}
function demo2(){
document.getElementById("green").style = "background-color:green";
document.getElementById("green").innerHTML = j;
if(j==0){
clear2();
demo3();
interval = setInterval(demo3,1000);
return;
}
j--;
}
function demo3(){
document.getElementById("yellow").style = "background-color:yellow";
document.getElementById("yellow").innerHTML = k;
if(k==0){
clear3();
demo1();
interval = setInterval(demo1,1000);
return;
}
k--;
}
function clear1(){
clearInterval(interval);
document.getElementById("red").style = "background-color:darkgrey";
document.getElementById("red").innerHTML = " red ";
i = 2;
}
function clear2(){
clearInterval(interval);
document.getElementById("green").style = "background-color:darkgrey";
document.getElementById("green").innerHTML = " green ";
j = 2;
}
function clear3(){
clearInterval(interval);
document.getElementById("yellow").style = "background-color:darkgrey";
document.getElementById("yellow").innerHTML = " yellow ";
k = 3;
}
</script>
</html>
边栏推荐
- MySQL2
- (2022 Niuke multi school III) j-journey (Dijkstra)
- Generics -- learn it, and there are many benefits
- C语言程序设计 | 程序编译与预处理
- C语言 pthread_cleanup_push()和pthread_cleanup_pop()函数(用于临界资源程序段中发生终止动作后的资源清理任务,以免造成死锁,临界区资源一般上锁)
- Want to sink into redis hash and write in the attributes and values of the object. Do the bosses have a demo?
- Binary tree -- natural search semantics (1) Basics
- C# 常用功能整合-3
- Li Mu hands-on learning, in-depth learning, V2 transformer and code implementation
- flink cdc 抽取oracle的数据,会不断的占用oracle的内存吗,最后引发ora-040
猜你喜欢

DDD Domain Driven Design Notes

Flutter实战-请求封装(一)

The possibility of metauniverse from the perspective of technical principles: how Omniverse "built" Mars

js做一个红绿灯

零号培训平台课程-1、SQL注入基础

C4D动画如何提交云渲染农场快速渲染?

Relevant principles of MySQL index optimization

C# 常用功能整合-2

(2022 Hangdian multi school III) 1011.taxi (Manhattan maximum + 2 points)

Usage of string class
随机推荐
Jmeter: interface automation test - BeanShell compares database data and return data
C# Winfrom 常用功能整合-2
MySQL limit paging query optimization practice
Drools(5):Drools高级语法
Golang controls the number of goroutines and obtains processing results
Oracle数据库问题
Codeforces Round #804 (Div. 2)(5/5)
Introduction to network -- overview of VLAN and trunk
Codeforces Round #804 (Div. 2)(5/5)
(posted) comparison of Eureka, consumer and Nacos 2
(2022杭电多校三)1009.Package Delivery(贪心)
Generics -- learn it, and there are many benefits
How to implement Devops with automation tools | including low code and Devops application practice
(2022 Hangdian multi school III) 1011.taxi (Manhattan maximum + 2 points)
Drools (5): drools advanced syntax
SQLite 常用功能整合
ADB instruction sorting
Bash: 创建返回布尔类型值的函数
请问 mysql timestamp(6) 用flink-sql接过来是 null,这点有办法处理不
Convert Excel to csv/csv UTF-8