Skip to content

Commit ce34b0b

Browse files
committed
add blurry loading
1 parent 8f87d2c commit ce34b0b

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

05-blurry loading/index.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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>Blurry Loading</title>
8+
</head>
9+
<body>
10+
<section class="bg"></section>
11+
<div class="loading-text">0%</div>
12+
<script src="script.js"></script>
13+
</body>
14+
</html>

05-blurry loading/script.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const loadText = document.querySelector(".loading-text");
2+
const bg = document.querySelector(".bg");
3+
4+
let load = 0;
5+
6+
const blurring = () => {
7+
load++;
8+
if (load > 99) clearInterval(int);
9+
loadText.innerText = `${load}%`;
10+
loadText.style.opacity = scale(load, 0, 100, 1, 0);
11+
bg.style.filter = `blur(${scale(load, 0, 100, 30, 0)}px)`;
12+
};
13+
14+
// For reference: https://stackoverflow.com/questions/10756313/javascript-jquery-map-a-range-of-numbers-to-another-range-of-numbers
15+
const scale = (num, in_min, in_max, out_min, out_max) => {
16+
return ((num - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min;
17+
};
18+
19+
let int = setInterval(blurring, 30);

05-blurry loading/style.css

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@import url("https://fonts.googleapis.com/css2?family=Ubuntu&display=swap");
2+
3+
* {
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
font-family: "Ubuntu", sans-serif;
9+
display: flex;
10+
align-items: center;
11+
justify-content: center;
12+
height: 100vh;
13+
overflow: hidden;
14+
margin: 0;
15+
}
16+
17+
.bg {
18+
background: url("https://images.unsplash.com/photo-1610217053402-b187336e9443?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=2100&q=80")
19+
no-repeat center center/cover;
20+
position: absolute;
21+
top: -30px;
22+
left: -30px;
23+
width: calc(100vw + 60px);
24+
height: calc(100vh + 60px);
25+
z-index: -1;
26+
filter: blur(0px);
27+
}
28+
29+
.loading-text {
30+
font-size: 50px;
31+
color: #a3b1c3;
32+
}

0 commit comments

Comments
 (0)