Skip to content

Commit a904869

Browse files
create at 2023 02 01
0 parents commit a904869

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="style.css">
8+
<title>Refresh For New Color</title>
9+
</head>
10+
<body>
11+
<div class="color-container">
12+
<h1 class="color-code"></h1>
13+
</div>
14+
<script src="./script.js"></script>
15+
</body>
16+
</html>

script.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
let color_container = document.querySelector(".color-container")
2+
let color_code = document.querySelector(".color-code")
3+
4+
window.addEventListener("load", () => {
5+
let RGB_color = RandomColorGenerator()
6+
console.log(RGB_color)
7+
color_container.style.backgroundColor = RGB_color
8+
color_code.innerHTML = RGB_color
9+
})
10+
11+
12+
function RandomColorGenerator() {
13+
let red = Math.floor(Math.random() * 255)
14+
let blue = Math.floor(Math.random() * 255)
15+
let green = Math.floor(Math.random() * 255)
16+
17+
let rgb = `rgb(${red}, ${green}, ${blue})`
18+
19+
return rgb
20+
}
21+

style.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*{
2+
padding:0;
3+
margin:0;
4+
box-sizing:border-box;
5+
}
6+
body{
7+
font-family: monospace;
8+
}
9+
.color-container{
10+
width: 100%;
11+
height: 100vh;
12+
background-color: #ccc;
13+
display: flex;
14+
justify-content: center;
15+
align-items: center;
16+
}
17+
.color-code{
18+
font-size: 16px;
19+
user-select: none;
20+
}

0 commit comments

Comments
 (0)