css confetti

In this example below you will see how to do a css confetti with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by moonglows76, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright moonglows76 ©

Technologies

  • HTML
  • CSS
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>css confetti</title>
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div class="container">
  <div class="confetti"></div>
  <div class="confetti"></div>
  <div class="confetti"></div>
  <div class="confetti"></div>
  <div class="confetti"></div>
  <div class="confetti"></div>
  <div class="confetti"></div>
  <div class="confetti"></div>
  <div class="confetti"></div>
  <div class="confetti"></div>
</div>
  
  

</body>

</html>

/*Downloaded from https://www.codeseek.co/moonglows76/css-confetti-BRVrgZ */
html, body,
.container {
  width: 100%;
  height: 100%;
}

.confetti {
  width: 15px;
  height: 15px;
  background-color: #f2d74e;
  position: absolute;
  left: 50%;
  -webkit-animation: confetti 5s ease-in-out -2s infinite;
          animation: confetti 5s ease-in-out -2s infinite;
  -webkit-transform-origin: left top;
          transform-origin: left top;
}

.confetti:nth-child(1) {
  background-color: #f2d74e;
  left: 10%;
  -webkit-animation-delay: 0;
          animation-delay: 0;
}

.confetti:nth-child(2) {
  background-color: #95c3de;
  left: 20%;
  -webkit-animation-delay: -5s;
          animation-delay: -5s;
}

.confetti:nth-child(3) {
  background-color: #ff9a91;
  left: 30%;
  -webkit-animation-delay: -3s;
          animation-delay: -3s;
}

.confetti:nth-child(4) {
  background-color: #f2d74e;
  left: 40%;
  -webkit-animation-delay: -2.5s;
          animation-delay: -2.5s;
}

.confetti:nth-child(5) {
  background-color: #95c3de;
  left: 50%;
  -webkit-animation-delay: -4s;
          animation-delay: -4s;
}

.confetti:nth-child(6) {
  background-color: #ff9a91;
  left: 60%;
  -webkit-animation-delay: -6s;
          animation-delay: -6s;
}

.confetti:nth-child(7) {
  background-color: #f2d74e;
  left: 70%;
  -webkit-animation-delay: -1.5s;
          animation-delay: -1.5s;
}

.confetti:nth-child(8) {
  background-color: #95c3de;
  left: 80%;
  -webkit-animation-delay: -2s;
          animation-delay: -2s;
}

.confetti:nth-child(9) {
  background-color: #ff9a91;
  left: 90%;
  -webkit-animation-delay: -3.5s;
          animation-delay: -3.5s;
}

.confetti:nth-child(10) {
  background-color: #f2d74e;
  left: 100%;
  -webkit-animation-delay: -2.5s;
          animation-delay: -2.5s;
}

@-webkit-keyframes confetti {
  0% {
    -webkit-transform: rotateZ(15deg) rotateY(0deg) translate(0, 0);
            transform: rotateZ(15deg) rotateY(0deg) translate(0, 0);
  }
  25% {
    -webkit-transform: rotateZ(5deg) rotateY(360deg) translate(-5vw, 20vh);
            transform: rotateZ(5deg) rotateY(360deg) translate(-5vw, 20vh);
  }
  50% {
    -webkit-transform: rotateZ(15deg) rotateY(720deg) translate(5vw, 60vh);
            transform: rotateZ(15deg) rotateY(720deg) translate(5vw, 60vh);
  }
  75% {
    -webkit-transform: rotateZ(5deg) rotateY(1080deg) translate(-10vw, 80vh);
            transform: rotateZ(5deg) rotateY(1080deg) translate(-10vw, 80vh);
  }
  100% {
    -webkit-transform: rotateZ(15deg) rotateY(1440deg) translate(10vw, 110vh);
            transform: rotateZ(15deg) rotateY(1440deg) translate(10vw, 110vh);
  }
}

@keyframes confetti {
  0% {
    -webkit-transform: rotateZ(15deg) rotateY(0deg) translate(0, 0);
            transform: rotateZ(15deg) rotateY(0deg) translate(0, 0);
  }
  25% {
    -webkit-transform: rotateZ(5deg) rotateY(360deg) translate(-5vw, 20vh);
            transform: rotateZ(5deg) rotateY(360deg) translate(-5vw, 20vh);
  }
  50% {
    -webkit-transform: rotateZ(15deg) rotateY(720deg) translate(5vw, 60vh);
            transform: rotateZ(15deg) rotateY(720deg) translate(5vw, 60vh);
  }
  75% {
    -webkit-transform: rotateZ(5deg) rotateY(1080deg) translate(-10vw, 80vh);
            transform: rotateZ(5deg) rotateY(1080deg) translate(-10vw, 80vh);
  }
  100% {
    -webkit-transform: rotateZ(15deg) rotateY(1440deg) translate(10vw, 110vh);
            transform: rotateZ(15deg) rotateY(1440deg) translate(10vw, 110vh);
  }
}

Comments