循环变化的颜色


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>循环变化的颜色</title>
<style>

width: 300px;
height: 300px;
border-radius: 300px;
background: orange;
}
</style>
</head>

<body>
<div class="wrap">
<div id="box" onclick="fun1()">
</div>
</div>
</body>

</html>
<script>
var box = document.getElementById('box')

function () {
box.style.background = 'black'
setTimeout(fun2, 500)
}

function fun2() {
box.style.background = 'green'
setTimeout(fun3, 500)
}

function fun3() {
box.style.background = 'red'
clearTimeout(setTimeout(fun2, 500))
}
</script>