cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class='container'>
  <div class='cube-container'>
    <div class='cube spincube'>
      <div class='face front'></div>
      <div class='face top'></div>
      <div class='face back'></div>
      <div class='face bottom'></div>
      <div class='face right'></div>
      <div class='face left'></div>
    </div>
  </div>
  <div class='controls'>
    <div class='buttons'>
      <button class='startSpin'>Spin</button>
      <button class='stopSpin'>Stop</button>
    </div>
    <div class='slider'>
      <label for='cube-size'>Cube Size</label>
      <input type="range" name="cube-size" class="size-slider" min="10" max="400" step="1" value="300">
      </div>
        
  </div>
</div>
            
          
!
            
              * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --side-size: 300px;
}

body {
  background: #f2f2f2;
}

.container {
  align-items: center;
  display: flex;
  flex-direction: column;
  height: 100vh;
  justify-content: space-between;
  margin-top: 145px;
  width: 100vw;
}

.cube-container {
  width: var(--side-size);
  height: var(--side-size);
}

.controls {
  bottom: 0;
  display: flex;
  flex-direction: column;
  height: 100px;
  justify-content: space-around;
   position: fixed;
  width: 650px;
}

.buttons {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  margin: 0 auto;
  width: 150px;
}

.slider {
  display: flex;
  justify-content: space-between;
  margin: 0 auto;
}

button, .slider {
  background: #545454;
  border: 5px solid coral;
  border-radius: 10px;
  color: white;
  font-size: 20px;
  height: 40px;
  padding: 5px;
}

button:focus {
  outline: none;
}

button:hover {
  background: #767676;
}

button:active {
  border: inset 5px coral;
  background: #323232;
}

.size-slider {
  align-self: center;
  width:400px;
  height:40px;
}

.cube {
  height: 100%;
  transform: rotateX(-45deg) rotateY(45deg) rotateZ(0deg);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  width: 100%;
}

.face {
  box-shadow: inset 0 0 calc(var(--side-size) / 10) rgba(0, 0, 0, 0.5);
  display: block;
  position: absolute;
  width: var(--side-size);
  height: var(--side-size);
  border: none;
}

.front {
  background: rgba(0, 0, 0, 0.3);
  transform: rotateX(0deg) rotateY(0deg) translateZ(calc(var(--side-size)/2));
  -webkit-transform: rotateX(0deg) rotateY(0deg) translateZ(calc(var(--side-size)/2));
}

.top {
  background: rgba(196, 196, 0, 0.6);
  transform: rotateX(90deg) rotateY(0deg) translateZ(calc(var(--side-size)/2));
  -webkit-transform: rotateX(90deg) rotateY(0deg) translateZ(calc(var(--side-size)/2))
}

.back {
  background: rgba(0, 255, 0, 0.6);
  color: black;
  transform: rotateX(0deg) rotateY(180deg) translateZ(calc(var(--side-size)/2));
  -webkit-transform: rotateX(0deg) rotateY(180deg) translateZ(calc(var(--side-size)/2));
}

.bottom {
  background: rgba(196, 0, 196, 0.6);
  transform: rotateX(-90deg) rotateY(0deg) translateZ(calc(var(--side-size)/2));
  -webkit-transform: rotateX(-90deg) rotateY(0deg) translateZ(calc(var(--side-size)/2));
}

.right {
  background: rgba(196, 0, 0, 0.6);
  transform: rotateX(0deg) rotateY(90deg) translateZ(calc(var(--side-size)/2));
  -webkit-transform: rotateX(0deg) rotateY(90deg) translateZ(calc(var(--side-size)/2));
}

.left {
    background: rgba(0, 0, 196, 0.6);
  transform: rotateX(0deg) rotateY(-90deg) translateZ(calc(var(--side-size)/2));
  -webkit-transform: rotateX(0deg) rotateY(-90deg) translateZ(calc(var(--side-size)/2));
}

.spincube {
  -webkit-animation-name: spincube;
  -webkit-animation-timing-function: ease-in-out;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-duration: 6s;
  animation-name: spincube;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-duration: 6s;
}

  @-webkit-keyframes spincube {
    from,to  { -webkit-transform: rotateX(-45deg) rotateY(45deg) rotateZ(0deg); }
    12.5% { 
      -webkit-transform: rotateX(45deg) rotateY(-45deg);       }
    25% { 
      -webkit-transform: rotateY(45deg) rotateZ(90deg);       }
    37.5% { 
      -webkit-transform: rotateY(-135deg);  
    }
    50% { 
      -webkit-transform: rotateX(135deg) rotateY(-225deg) rotateZ(180deg);
    }
    62.5% { 
      -webkit-transform: rotateX(-225deg) rotateY(-45deg);
    }
    75% {
      -webkit-transform: rotateX(225deg) rotateY(135deg) rotateZ(270deg);
    }
    87.5% {
      -webkit-transform: rotateX(315deg) rotateY(-315deg);
    }
  }

  @keyframes spincube {
    from,to {
      -moz-transform: rotateX(-45deg) rotateY(45deg) rotateZ(0deg);
      -ms-transform: rotateX(-45deg) rotateY(45deg) rotateZ(0deg);
      transform: rotateX(-45deg) rotateY(45deg) rotateZ(0deg);
    }
    12.5% {
      -moz-transform: rotateX(45deg) rotateY(-45deg);
      -ms-transform: rotateX(45deg) rotateY(-45deg);
      transform: rotateX(45deg) rotateY(-45deg);
    }
    25% {
      -moz-transform: rotateY(45deg) rotateZ(90deg);
      -ms-transform: rotateY(45deg) rotateZ(90deg);
      transform: rotateY(45deg) rotateZ(90deg);
    }
    37.5% {
      -moz-transform: rotateY(-135deg);
      -ms-transform: rotateY(-135deg);
      transform: rotateY(-135deg);
    }
    50% {
      -moz-transform: rotateX(135deg) rotateY(-225deg) rotateZ(180deg);
      -ms-transform: rotateX(135deg) rotateY(-225deg) rotateZ(180deg);
      transform: rotateX(135deg) rotateY(-225deg) rotateZ(180deg);
    }
    62.5% {
      -moz-transform: rotateX(-225deg) rotateY(-45deg);
      -ms-transform: rotateX(-225deg) rotateY(-45deg);
      transform: rotateX(-225deg) rotateY(-45deg);
    }
    75% {
      -moz-transform: rotateX(225deg) rotateY(135deg) rotateZ(270deg);
      -ms-transform: rotateX(225deg) rotateY(135deg) rotateZ(270deg);
      transform: rotateX(225deg) rotateY(135deg) rotateZ(270deg);
    }
    87.5% {
      -moz-transform: rotateX(315deg) rotateY(-315deg);
      -ms-transform: rotateX(315deg) rotateY(-315deg);
      transform: rotateX(315deg) rotateY(-315deg);
    }
  } 
            
          
!
            
              const cube = document.querySelector('.cube');
 
const startButton = document.querySelector('.startSpin');
const stopButton = document.querySelector('.stopSpin');

startButton.addEventListener('click', spinCube);
stopButton.addEventListener('click', resetCube);

function spinCube(){
  cube.classList.add('spincube');
}

function resetCube() {
  cube.classList.remove('spincube');
  cube.style.transform = 'rotateX(-45deg) rotateY(45deg) rotateZ(0deg)';
}

const slider = document.querySelector('.size-slider')

slider.addEventListener('change', changeCube);
slider.addEventListener('mousemove', changeCube);

function changeCube(e){
  const size = e.target.value;
  document.body.style.setProperty('--side-size', `${size}px`);
}
            
          
!
999px
Loading ..................

Console