-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.html
39 lines (34 loc) · 1.19 KB
/
button.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
#body {
width: 100vw;
height: 100vh;
background-color: rgb(134, 134, 241);
}
#click {
position: absolute;
top: 50%;
left: 50%;
color: rgb(8, 8, 8);
background-color: rgb(57, 226, 35);
}
</style>
<body>
<button id="click" onclick="myFunction">Click Me</button>
<script>
var colors = ["blue", "green", "gray", "yellow", "black", "red", "pink", "white"], // the color choices Blue, green, grey, yellow, black, red, pink, white
index = 0; // index of the current color
document.getElementById("click").onclick = function() {
document.body.style.background = colors[index]; // set the color of body to the current color
index = (index + 1) % colors.length; // increment index to point to the next color (if it goes beyond the length of the coices array get it back to 0 using the modulo %)
}
</script>
</body>
</html>