Creating Preloader screen with CSS is pretty easy due to added animation to them. CSS also unlock lots of designing opportunity by providing lot of psuedo-elements like :before, :after etc.
Steps required to create css preloader
- A web page (Hypertext Markup Language page)
- Cascading Style Sheet (CSS)
- Additionally, JavaScript can be used for hiding the preloading screen after page completes its loading.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple Circle loading</title>
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<div class="overlay">
<div class="loader"></div>
</div>
</body>
</html>
CSS
*{
padding: 0;
margin: 0;
}
.overlay{
background: #425632;
width:100%;
height: 100vh;
position: fixed;
animation: bgRotate 2s infinite ease-in-out;
}
.loader{
border: 60px solid #000000;
position:absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-radius: 50%;
animation: rotateAndSpilt 2s infinite ease-in-out;
}
@keyframes rotateAndSpilt{
0%{
transform: translate(-50%, -50%) rotate(0deg);
width: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid #000000;
border-right: 60px solid #000000;
}
50%{
transform: translate(-50%, -50%) rotate(180deg);
width: 0;
border-top: 60px solid #ffffff;
border-bottom: 60px solid #ffffff;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
}
100%{
transform: translate(-50%, -50%) rotate(360deg);
width: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid #000000;
border-right: 60px solid #000000;
}
}
@keyframes bgRotate{
0%{
background: #ffffff;
}
50%{
background: #000000;
}
100%{
background: #ffffff;
}
}
JavaScript
window.onload = function(){
document.getElementsByClassName("overlay")[0].style.display = "none";
/* [0] <= coz. we are considering overlay class for loader is at index 0 or first position */
};
Comments
Post a Comment