Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel includes JSX processing.

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.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <head>
    <script type="module" src="https://cdn.jsdelivr.net/npm/@proyecto26/animatable-component@1.1.10/dist/animatable-component/animatable-component.esm.js"></script>
  </head>
  <body>
    <div class="clock">
      <animatable-component>
        <div class="cube">
          <div class="front face">
            <div class="text lastHours"></div>
          </div>
          <div class="back face">
            <div class="text"></div>
          </div>
          <div class="right face">
            <div class="text"></div>
          </div>
          <div class="left face">
            <div class="text"></div>
          </div>
          <div class="top face">
            <div class="text nowHours"></div>
          </div>
          <div class="bottom face">
            <div class="text"></div>
          </div>
        </div>
      </animatable-component>
      <animatable-component>
        <div class="cube">
          <div class="front face">
            <div class="text lastMinutes"></div>
          </div>
          <div class="back face">
            <div class="text"></div>
          </div>
          <div class="right face">
            <div class="text"></div>
          </div>
          <div class="left face">
            <div class="text"></div>
          </div>
          <div class="top face">
            <div class="text nowMinutes"></div>
          </div>
          <div class="bottom face">
            <div class="text"></div>
          </div>
        </div>
      </animatable-component>
      <animatable-component>
        <div class="cube">
          <div class="front face">
            <div class="text lastSeconds"></div>
          </div>
          <div class="back face">
            <div class="text"></div>
          </div>
          <div class="right face">
            <div class="text"></div>
          </div>
          <div class="left face">
            <div class="text"></div>
          </div>
          <div class="top face">
            <div class="text nowSeconds"></div>
          </div>
          <div class="bottom face">
            <div class="text"></div>
          </div>
        </div>
      </animatable-component>
    </div>
    <div class="controls">
      <div>
        <h2>Size</h2>
        <input id="size" type="range" min="50" max="260" value="150" />
      </div>
      <div>
        <h2>Perspective</h2>
        <input id="perspective" type="range" min="400" max="1000" value="1000" />
      </div>
      <div>
        <h2>Perspective X-axis</h2>
        <input id="perspective_x" type="range" min="-200" max="200" value="50" />
      </div>
      <div>
        <h2>Perspective Y-axis</h2>
        <input id="perspective_y" type="range" min="-200" max="200" value="50" />
      </div>
    </div>
  </body>
</html>
              
            
!

CSS

              
                :root {
  --size: 150;
  --perspective: 1000;
  --perspective_x: 50;
  --perspective_y: 50;
  --background: linear-gradient(to right, #8e2de2, #4a00e0);
}

html, body {
  height: 100%;
}
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #1D1E26;
}
.clock {
  flex-direction: row;
  display: flex;
  width: 100%;
}
animatable-component, .cube, .face {
  width: calc(var(--size) * 1px);
  max-width: 100%;
  height: calc(var(--size) * 1px);
}
animatable-component {
  perspective: calc(var(--perspective) * 1px);
  perspective-origin: calc(var(--perspective_x) * 1%) calc(var(--perspective_y) * 1%);
  height: 100%;
  width: 100%;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cube {
  display: block;
  position: relative;
  background: transparent;
  transform-style: preserve-3d;
  transform: translateZ(-calc((var(--size) * 1px)/2));
}
.face {
  background: var(--background);
  position: absolute;
  height: 100%;
  width: 100%;
  border: 2px solid black;
  line-height: 260px;
  font-size: 40px;
  font-weight: bold;
  text-align: center;
}
.front {
  transform:
    rotateY(0deg)
    translateZ(calc((var(--size) * 1px)/2));
  will-change: transform;
}
.back {
  transform:
    rotateY(180deg)
    translateZ(calc((var(--size) * 1px)/2));
  will-change: transform;
}
.right {
  transform:
    rotateY(90deg)
    translateZ(calc((var(--size) * 1px)/2));
  will-change: transform;
}
.left {
  transform:
    rotateY(-90deg)
    translateZ(calc((var(--size) * 1px)/2));
  will-change: transform;
}
.top {
  transform:
    rotateX(90deg)
    translateZ(calc((var(--size) * 1px)/2));
  will-change: transform;
}
.bottom {
  transform:
    rotateX(-90deg)
    translateZ(calc((var(--size) * 1px)/2));
  will-change: transform;
}
.text {
  color: #fff;
  font-size: calc((var(--size) * 1px)/2);
  text-align: center;
  position: absolute;
  width: 100%;
  line-height: calc(var(--size) * 1px);
}

.controls {
  height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.controls div {
  display: flex;
  flex-direction: row;
  height: 30px;
  align-items: center;
  align-self: center;
}
h2 {
  color: white;
  padding-right: 5px;
}
              
            
!

JS

              
                /**
 * <animatable/> WebComponent => https://github.com/proyecto26/animatable-component
 */

const animatables = document.querySelectorAll('animatable-component');
[...animatables].forEach((animatable) => {
  animatable.options = {
    duration: 800, //less than 1 second
    fill: 'both', //none, forwards, backwards, both
    easing: 'cubic-bezier(0.250, 0.460, 0.450, 0.940)', // easing functions or custom function
    composite: 'replace', //replace, add, accumulate
    direction: 'normal', //normal, reverse, alternate, alternate-reverse
    iterations: 1, // Infinity
    delay: 100
  }
  animatable.keyFrames = [
    { offset: 0, transform: `rotateX(0deg)`, fill: 'both' },
    { offset: 1, transform: `rotateX(-90deg)`, fill: 'both' }
  ]
  customElements.whenDefined('animatable-component').then(() => {
    animatable.play()
  })
})

const lastHours = document.querySelector('.lastHours')
const nowHours = document.querySelector('.nowHours')
const lastMinutes = document.querySelector('.lastMinutes')
const nowMinutes = document.querySelector('.nowMinutes')
const lastSeconds = document.querySelector('.lastSeconds')
const nowSeconds = document.querySelector('.nowSeconds')

lastHours.innerText = '--'
lastMinutes.innerText = '--'
lastSeconds.innerText = '--'
nowHours.innerText = new Date().getHours()
nowMinutes.innerText = new Date().getMinutes()
nowSeconds.innerText = new Date().getSeconds()
setInterval(function() {
  const now = new Date()
  const hours = now.getHours() + ''
  const minutes = now.getMinutes() + ''
  const seconds = now.getSeconds() + ''
  if (nowHours.innerText !== hours) {
    lastHours.innerText = nowHours.innerText
    lastHours.closest('animatable-component').play()
    nowHours.innerHTML = hours
  }
  if (nowMinutes.innerText !== minutes) {
    lastMinutes.innerText = nowMinutes.innerText
    lastMinutes.closest('animatable-component').play()
    nowMinutes.innerHTML = minutes
  }
  if (nowSeconds.innerText !== seconds) {
    lastSeconds.innerText = nowSeconds.innerText
    lastSeconds.closest('animatable-component').play()
    nowSeconds.innerHTML = seconds
  }
}, 1000)


/**
 * Resize cubes! <3
 */
const documentStyle = document.documentElement.style;
document.querySelectorAll('input').forEach(input => {
  input.addEventListener('input', function(e) { 
    documentStyle.setProperty('--' + e.currentTarget.id, e.currentTarget.value);
  });
})
              
            
!
999px

Console