Skip to content

Commit 6d75e73

Browse files
authored
HOVERBOARD
1 parent 3948690 commit 6d75e73

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

project 36/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link rel="stylesheet" href="style.css" />
7+
<title>Project 36 Hoverboard</title>
8+
</head>
9+
<body>
10+
<div class="container" id="container"></div>
11+
<script src="script.js"></script>
12+
</body>
13+
</html>

project 36/script.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const container = document.getElementById("container");
2+
const colors = ["#e74c3c", "#8e44ad", "#3498db", "#e67e22", "#2ecc71"];
3+
const SQUARES = 500;
4+
5+
for (let i = 0; i < SQUARES; i++) {
6+
const square = document.createElement("div");
7+
square.classList.add("square");
8+
9+
square.addEventListener("mouseover", () => setColor(square));
10+
11+
square.addEventListener("mouseout", () => removeColor(square));
12+
13+
container.appendChild(square);
14+
}
15+
16+
function setColor(element) {
17+
const color = getRandomColor();
18+
element.style.background = color;
19+
element.style.boxShadow = `0 0 2px ${color}, 0 0 10px ${color}`;
20+
}
21+
22+
function removeColor(element) {
23+
element.style.background = "#1d1d1d";
24+
element.style.boxShadow = "0 0 2px #000";
25+
}
26+
27+
function getRandomColor() {
28+
return colors[Math.floor(Math.random() * colors.length)];
29+
}

project 36/style.css

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
* {
2+
box-sizing: border-box;
3+
}
4+
5+
body {
6+
background-color: #111;
7+
display: flex;
8+
align-items: center;
9+
justify-content: center;
10+
height: 100vh;
11+
overflow: hidden;
12+
margin: 0;
13+
}
14+
15+
.container {
16+
display: flex;
17+
align-items: center;
18+
justify-content: center;
19+
flex-wrap: wrap;
20+
max-width: 400px;
21+
}
22+
23+
.square {
24+
background-color: #1d1d1d;
25+
box-shadow: 0 0 2px #000;
26+
height: 16px;
27+
width: 16px;
28+
margin: 2px;
29+
transition: 2s ease;
30+
}
31+
32+
.square:hover {
33+
transition-duration: 0s;
34+
}

0 commit comments

Comments
 (0)