Blurry loading screen animation | loading animation using html css javascript – codewithrandom







Blurry loading screen animation | loading animation using html css javascript – codewithrandom

Welcome🎉 to Code With Random blog. In this blog, we learn that how we create a blurry loading screen animation. We use HTML, Css, and javascript for this blurry loading screen animation. Hope you enjoy our blog so let’s start with a basic HTML structure for a blurry loading screen animation. 

HTML code

 <!DOCTYPE html>  
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title> blurry loading screen animation </title>
</head>
<body>
<section class="bg"></section>
<div class="loading-text">0%</div>
</body>
</html>

There is all HTML code for the blurry loading screen animation. Now, you can see output without CSS, then we write css & javascript for the blurry loading screen animation.

output

Blurry loading screen animation | loading animation using html css javascript - codewithrandom

CSS Code

 @import url("https://fonts.googleapis.com/css2?family=Ubuntu&display=swap");  
* {
box-sizing: border-box;
}
body {
font-family: "Ubuntu", sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
margin: 0;
}
.bg {
background: url("./car2.jpg")
no-repeat center center / cover;
position: absolute;
top: -30px;
left: -30px;
width: calc(100vw + 60px);
height: calc(100vh + 60px);
z-index: -1;
filter: blur(0px);
}
.loading-text {
font-size: 50px;
color: #a3b1c3;
}

Now we have completed our CSS section,  Here is our updated output CSS.

output

Blurry loading screen animation | loading animation using html css javascript - codewithrandom

Javascript code 

 const loadText = document.querySelector(".loading-text");  
const bg = document.querySelector(".bg");
let load = 0;
const blurring = () => {
load++;
if (load > 99) clearInterval(int);
loadText.innerText = `${load}%`;
loadText.style.opacity = scale(load, 0, 100, 1, 0);
bg.style.filter = `blur(${scale(load, 0, 100, 30, 0)}px)`;
};

const scale = (num, in_min, in_max, out_min, out_max) => {
return ((num - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min;
};
let int = setInterval(blurring, 30);

Final output


Now we have completed our javascript section,  Here is our updated output with javascriptHope you like the blurry loading screen. you can see output video and project screenshots. See our other blogs and gain knowledge in front-end development. Thank you 🙏💕!

In this post, we learn how to create a blurry loading screen using simple HTML & CSS, and javascript. If we made a mistake or any confusion, please drop a comment to reply or help you in easy learning.

Written by – Code With Random/Anki 

Share on:

Leave a Comment