Pure CSS slot machine

In this example below you will see how to do a Pure CSS slot machine with some HTML / CSS and Javascript

A slot machine animation using SCSS to calculate 3d rotations and randomize numbers.

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

Technologies

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

<head>
  <meta charset="UTF-8">
  <title>Pure CSS slot machine</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='machine'>
  <div class='slots'>
    <ul class='slot'>
      <li class='number'>0</li>
      <li class='number'>1</li>
      <li class='number'>2</li>
      <li class='number'>3</li>
      <li class='number'>4</li>
      <li class='number'>5</li>
      <li class='number'>6</li>
      <li class='number'>7</li>
      <li class='number'>8</li>
      <li class='number'>9</li>
    </ul>
    <ul class='slot'>
      <li class='number'>0</li>
      <li class='number'>1</li>
      <li class='number'>2</li>
      <li class='number'>3</li>
      <li class='number'>4</li>
      <li class='number'>5</li>
      <li class='number'>6</li>
      <li class='number'>7</li>
      <li class='number'>8</li>
      <li class='number'>9</li>
    </ul>
    <ul class='slot'>
      <li class='number'>0</li>
      <li class='number'>1</li>
      <li class='number'>2</li>
      <li class='number'>3</li>
      <li class='number'>4</li>
      <li class='number'>5</li>
      <li class='number'>6</li>
      <li class='number'>7</li>
      <li class='number'>8</li>
      <li class='number'>9</li>
    </ul>
  </div>
</div>
  
  

</body>

</html>

/*Downloaded from https://www.codeseek.co/brandoncash/pure-css-slot-machine-YpWELE */
.machine {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100vw;
  height: 60vw;
  -webkit-transform: translate3d(-50%, -50%, 0);
          transform: translate3d(-50%, -50%, 0);
  background-color: red;
}

.slots {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 90vw;
  height: 40vw;
  -webkit-transform: translate3d(-50%, -50%, 0);
          transform: translate3d(-50%, -50%, 0);
  -webkit-perspective: 800vw;
          perspective: 800vw;
  overflow: hidden;
  background-color: #050505;
  box-shadow: 1vw 1vw 2vw #ff8f8f, -1vw -1vw 2vw #000, -1vw 1vw 2vw #000, 1vw -1vw 2vw #000;
}
.slots:after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.8) 12%, rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0) 70%, rgba(0, 0, 0, 0.8) 90%, black 100%);
}

.slot {
  position: absolute;
  top: 0vw;
  width: 30%;
  height: 20vw;
  margin: 0;
  padding: 0;
  list-style-type: none;
  background-color: rgba(255, 255, 255, 0.1);
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
  -webkit-transform-origin: 50% 100%;
          transform-origin: 50% 100%;
  -webkit-animation-timing-function: linear;
          animation-timing-function: linear;
  -webkit-animation-iteration-count: 1;
          animation-iteration-count: 1;
  -webkit-animation-fill-mode: both;
          animation-fill-mode: both;
}
.slot:nth-child(1) {
  left: 3%;
  -webkit-animation-name: rotate-1;
          animation-name: rotate-1;
  -webkit-animation-duration: 5s;
          animation-duration: 5s;
}
.slot:nth-child(2) {
  left: 35%;
  -webkit-animation-name: rotate-2;
          animation-name: rotate-2;
  -webkit-animation-duration: 6s;
          animation-duration: 6s;
}
.slot:nth-child(3) {
  left: 67%;
  -webkit-animation-name: rotate-2;
          animation-name: rotate-2;
  -webkit-animation-duration: 5.4s;
          animation-duration: 5.4s;
}

@-webkit-keyframes rotate-1 {
  0% {
    -webkit-transform: rotateX(324deg);
            transform: rotateX(324deg);
  }
  50% {
    -webkit-transform: rotateX(-900deg);
            transform: rotateX(-900deg);
  }
  70% {
    -webkit-transform: rotateX(-1260deg);
            transform: rotateX(-1260deg);
  }
  90% {
    -webkit-transform: rotateX(-1584deg);
            transform: rotateX(-1584deg);
  }
  100% {
    -webkit-transform: rotateX(-1620deg);
            transform: rotateX(-1620deg);
  }
}

@keyframes rotate-1 {
  0% {
    -webkit-transform: rotateX(324deg);
            transform: rotateX(324deg);
  }
  50% {
    -webkit-transform: rotateX(-900deg);
            transform: rotateX(-900deg);
  }
  70% {
    -webkit-transform: rotateX(-1260deg);
            transform: rotateX(-1260deg);
  }
  90% {
    -webkit-transform: rotateX(-1584deg);
            transform: rotateX(-1584deg);
  }
  100% {
    -webkit-transform: rotateX(-1620deg);
            transform: rotateX(-1620deg);
  }
}
@-webkit-keyframes rotate-2 {
  0% {
    -webkit-transform: rotateX(0deg);
            transform: rotateX(0deg);
  }
  50% {
    -webkit-transform: rotateX(-1044deg);
            transform: rotateX(-1044deg);
  }
  70% {
    -webkit-transform: rotateX(-1404deg);
            transform: rotateX(-1404deg);
  }
  90% {
    -webkit-transform: rotateX(-1728deg);
            transform: rotateX(-1728deg);
  }
  100% {
    -webkit-transform: rotateX(-1764deg);
            transform: rotateX(-1764deg);
  }
}
@keyframes rotate-2 {
  0% {
    -webkit-transform: rotateX(0deg);
            transform: rotateX(0deg);
  }
  50% {
    -webkit-transform: rotateX(-1044deg);
            transform: rotateX(-1044deg);
  }
  70% {
    -webkit-transform: rotateX(-1404deg);
            transform: rotateX(-1404deg);
  }
  90% {
    -webkit-transform: rotateX(-1728deg);
            transform: rotateX(-1728deg);
  }
  100% {
    -webkit-transform: rotateX(-1764deg);
            transform: rotateX(-1764deg);
  }
}
@-webkit-keyframes rotate-3 {
  0% {
    -webkit-transform: rotateX(108deg);
            transform: rotateX(108deg);
  }
  50% {
    -webkit-transform: rotateX(-828deg);
            transform: rotateX(-828deg);
  }
  70% {
    -webkit-transform: rotateX(-1188deg);
            transform: rotateX(-1188deg);
  }
  90% {
    -webkit-transform: rotateX(-1512deg);
            transform: rotateX(-1512deg);
  }
  100% {
    -webkit-transform: rotateX(-1548deg);
            transform: rotateX(-1548deg);
  }
}
@keyframes rotate-3 {
  0% {
    -webkit-transform: rotateX(108deg);
            transform: rotateX(108deg);
  }
  50% {
    -webkit-transform: rotateX(-828deg);
            transform: rotateX(-828deg);
  }
  70% {
    -webkit-transform: rotateX(-1188deg);
            transform: rotateX(-1188deg);
  }
  90% {
    -webkit-transform: rotateX(-1512deg);
            transform: rotateX(-1512deg);
  }
  100% {
    -webkit-transform: rotateX(-1548deg);
            transform: rotateX(-1548deg);
  }
}
.number {
  position: absolute;
  top: 10vw;
  right: 0;
  left: 0;
  display: flex;
  height: 20vw;
  justify-content: center;
  align-items: center;
  font-size: 8vw;
  box-shadow: inset 0 0 2vw rgba(0, 0, 0, 0.8), inset 0 0 0.5vw rgba(0, 0, 0, 0.5);
  background-color: rgba(204, 193, 163, 0.95);
  -webkit-transform-origin: 50% 50%;
          transform-origin: 50% 50%;
}

.number:nth-child(0) {
  -webkit-transform: rotateX(0deg) translateZ(30vw);
          transform: rotateX(0deg) translateZ(30vw);
}

.number:nth-child(1) {
  -webkit-transform: rotateX(36deg) translateZ(30vw);
          transform: rotateX(36deg) translateZ(30vw);
}

.number:nth-child(2) {
  -webkit-transform: rotateX(72deg) translateZ(30vw);
          transform: rotateX(72deg) translateZ(30vw);
}

.number:nth-child(3) {
  -webkit-transform: rotateX(108deg) translateZ(30vw);
          transform: rotateX(108deg) translateZ(30vw);
}

.number:nth-child(4) {
  -webkit-transform: rotateX(144deg) translateZ(30vw);
          transform: rotateX(144deg) translateZ(30vw);
}

.number:nth-child(5) {
  -webkit-transform: rotateX(180deg) translateZ(30vw);
          transform: rotateX(180deg) translateZ(30vw);
}

.number:nth-child(6) {
  -webkit-transform: rotateX(216deg) translateZ(30vw);
          transform: rotateX(216deg) translateZ(30vw);
}

.number:nth-child(7) {
  -webkit-transform: rotateX(252deg) translateZ(30vw);
          transform: rotateX(252deg) translateZ(30vw);
}

.number:nth-child(8) {
  -webkit-transform: rotateX(288deg) translateZ(30vw);
          transform: rotateX(288deg) translateZ(30vw);
}

.number:nth-child(9) {
  -webkit-transform: rotateX(324deg) translateZ(30vw);
          transform: rotateX(324deg) translateZ(30vw);
}

.number:nth-child(10) {
  -webkit-transform: rotateX(360deg) translateZ(30vw);
          transform: rotateX(360deg) translateZ(30vw);
}

body {
  background-color: #222;
}

Comments