Skip to content

Instantly share code, notes, and snippets.

@MedRedha
Created March 23, 2020 21:43
Show Gist options
  • Save MedRedha/80b8784f6248dbe1b553fa1d353c9f68 to your computer and use it in GitHub Desktop.
Save MedRedha/80b8784f6248dbe1b553fa1d353c9f68 to your computer and use it in GitHub Desktop.
Loader
<div id="circle_container">
<div id="stars"></div>
<div id="load_wrapper">
<div id="sun"></div>
<div id="moon"></div>
</div>
</div>
<h1 id="loading_text">Loading</h1>
function getRandom (size)
{
return Math.floor(Math.random() * size);
}
//Creating the layers for the stars
for (i = 2; i < 12; i++)
{
$("#stars").append('<div class="star_layer" style="transform: translateZ(' + i + 'px) scale(' + (15 - i)/(15) +');"></div>')
}
//Creating the stars
for (i = 0; i < 70; i++)
{
$(".star_layer").eq(getRandom(10)).append('<div class="star"></div>');
}
updateStars();
//Change stars every cycle
setInterval(updateStars, 4000);
//Randomising stars. Position and opacity is changed every cycle.
function updateStars ()
{
$(".star").each(function() {
$(this).css({"top": getRandom(200) + "px", "left": getRandom(200) + "px", "opacity": (20 + getRandom(50))/100});
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
*
{
margin: 0;
padding: 0;
}
/*Replace by a container if needed*/
body
{
height: 100vh;
width: 100%;
background-color: #DDD;
position: absolute;
}
#circle_container
{
height: 200px;
width: 200px;
position: absolute;
/*Centering*/
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
border-radius: 50%;
background-color: #DDD;
overflow: hidden;
animation: background 4s -3.5s infinite;
/*Nice modern drop-shadow*/
box-shadow: 0 8px 25px rgba(0,0,0,0.4);
}
#load_wrapper
{
height: 300%;
width: 300%;
margin-left: -50px;
transform: translate3d(-25%, 0, 0);
position: relative;
animation: rotation 4s linear infinite;
}
#sun, #moon
{
position: absolute;
border-radius: 50%;
/*Make sure they are in the middle*/
left: 50%;
transform: translateX(-50%);
}
#sun
{
width: 80px;
height: 80px;
background-color: #FFD475;
top: 40px;
box-shadow: 0 0 15px #FFCB57;
}
#moon
{
width: 50px;
height: 50px;
background-color: #EEE;
top: 450px;
box-shadow: 0 0 25px rgba(0,0,0,0.2) inset, 0 0 10px white;
}
#stars
{
/*Has to be more than the amount of layers*/
perspective: 15px;
width: 100%;
animation: stars 4s linear infinite;
opacity: 0.8;
}
.star
{
width: 4px;
height: 4px;
background-color: white;
position: absolute;
border-radius: 50%;
}
.star_layer
{
position: absolute;
width: 200px;
height: 200px;
/*This is to make sure the upper-Z layer's don't shift downward*/
transform-origin: 100px 0;
}
#loading_text
{
text-align: center;
font-family: 'Roboto', sans-serif;
position: absolute;
top: calc(50% - 135px);
transform: translateY(-50%);
width: 100%;
line-height: 1;
color: #555;
font-size: 40px;
}
@keyframes rotation
{
0% {
transform: translate3d(-25%, 0, 0) rotate(0deg);
}
20% {
/*Sun goes down*/
transform: translate3d(-25%, 0, 0) rotate(50deg);
}
30% {
/*Moon rises*/
transform: translate3d(-25%, 0, 0) rotate(130deg);
}
70% {
/*Moon goes down*/
transform: translate3d(-25%, 0, 0) rotate(240deg);
}
80% {
/*Sun rises*/
transform: translate3d(-25%, 0, 0) rotate(310deg);
}
100% {
transform: translate3d(-25%, 0, 0) rotate(360deg);
}
}
@keyframes background
{
0% {
background-color: #2896C3;
}
50% {
/*Night*/
background-color: #1E5267;
}
100% {
background-color: #2896C3;
}
}
@keyframes stars
{
0% {
/*Invisible, not moving*/
opacity: 0;
padding-right: 0;
}
25% {
/*Start of movement*/
opacity: 0;
padding-right: 0;
}
50% {
/*Visible*/
opacity: 1;
padding-right: 25px;
}
75% {
opacity: 0;
padding-right: 50px;
}
100% {
opacity: 0;
padding-right: 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment