Skip to content

Commit dcabe2d

Browse files
committed
add hoverboard effect
1 parent c3ce1fa commit dcabe2d

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

36-hoverboard/index.html

+13
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>Hoverboard</title>
8+
</head>
9+
<body>
10+
<div class="container" id="container"></div>
11+
<script src="script.js"></script>
12+
</body>
13+
</html>

36-hoverboard/script.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const container = document.getElementById("container");
2+
const colors = ["#056CF2", "#05AFF2", "#F2E205", "#F28705", "#A62103"];
3+
const SQUARES = 500;
4+
5+
const getRandomColor = () => colors[Math.floor(Math.random() * colors.length)];
6+
7+
const setColor = (square) => {
8+
const color = getRandomColor();
9+
square.style.background = color;
10+
square.style.boxShadow = `0 0 2px ${color}, 0 0 10px ${color}`;
11+
};
12+
13+
const removeColor = (square) => {
14+
square.style.background = "#1d1d1d";
15+
square.style.boxShadow = "0 0 2px #000";
16+
};
17+
18+
for (let i = 0; i < SQUARES; i++) {
19+
const square = document.createElement("div");
20+
square.classList.add("square");
21+
square.addEventListener("mouseover", () => setColor(square));
22+
square.addEventListener("mouseout", () => removeColor(square));
23+
container.appendChild(square);
24+
}

36-hoverboard/style.css

+34
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+
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
| 33 | [Notes App](https://github.com/solygambas/html-css-fifty-projects/tree/master/33-notes%20app) | [Live Demo](https://codepen.io/solygambas/full/qBavQog) |
4242
| 34 | [Animated Countdown](https://github.com/solygambas/html-css-fifty-projects/tree/master/34-animated%20countdown) | [Live Demo](https://codepen.io/solygambas/full/vYXPbYW) |
4343
| 35 | [Image Carousel](https://github.com/solygambas/html-css-fifty-projects/tree/master/35-image%20carousel) | [Live Demo](https://codepen.io/solygambas/full/zYKbQZK) |
44-
| 36 | [Hoverboard](https://github.com/solygambas/html-css-fifty-projects/tree/master/hoverboard) | [Live Demo](/hoverboard/) |
44+
| 36 | [Hoverboard](https://github.com/solygambas/html-css-fifty-projects/tree/master/36-hoverboard) | [Live Demo](https://codepen.io/solygambas/full/OJRqYKK) |
4545
| 37 | [Pokedex](https://github.com/solygambas/html-css-fifty-projects/tree/master/pokedex) | [Live Demo](/pokedex/) |
4646
| 38 | [Mobile Tab Navigation](https://github.com/solygambas/html-css-fifty-projects/tree/master/mobile-tab-navigation) | [Live Demo](/mobile-tab-navigation/) |
4747
| 39 | [Password Strength Background](https://github.com/solygambas/html-css-fifty-projects/tree/master/password-strength-background) | [Live Demo](/password-strength-background/) |

0 commit comments

Comments
 (0)