sun-animation

In this example below you will see how to do a sun-animation with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by cooproton, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright cooproton ©
  • HTML
  • CSS
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>sun-animation</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <section class="container">
  <div class="sky"></div>
  <div class="ground"></div>
  <div class="sun"></div>
</section>
  
  

</body>

</html>

/*Downloaded from https://www.codeseek.co/cooproton/sun-animation-aGoYbx */
.container {
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100vw;
  position: relative;
}

.sky {
  width: 100vw;
  height: 70%;
  background: #4d9fce;
  animation: sky 5s infinite;
}

.ground {
  width: 100vw;
  height: 30vh;
  background: #468401;
  animation: ground 5s infinite linear;
  position: relative;
  z-index: 5;
}

.sun {
  border-radius: 50%;
  background: yellow;
  height: 14rem;
  width: 14rem;
  position: absolute;
  top: 1rem;
  left: 40%;
  animation: sun 5s infinite linear;
  z-index: 2;
}

@keyframes sun {
  0% {
    top: 45rem;
    left: 0;
  }
  50% {
    top: 1rem;
    left: 40%;
  }
  100% {
    top: 45rem;
    left: 90rem;
  }
}
@keyframes ground {
  0% {
    background: #468401;
  }
  50% {
    background: #468401;
  }
  100% {
    background: #320404;
  }
}
@keyframes sky {
  0% {
    background: #4d9fce;
  }
  50% {
    background: #4d9fce;
  }
  100% {
    background: #9e0a0b;
  }
}

Comments