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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div class="clock">
  <div class="clock-inner">
    <p class="hours">  
      <span><span class="animator">&#3406;</span></span>
      <span id="hr">00</span>
    </p>
    <p class="minutes">
      <span><span class="animator">&#3406;</span></span>
      <span id="min">00</span>
    </p>
    <p class="seconds">
      <span><span class="animator">&#3406;</span></span>
      <span id="sec">00</span>
    </p>
  </div>
</div>
              
            
!

CSS

              
                body {
  font-size: 96px;
  color: #eee;
  background-color: #999;
}
.clock {
  height: 100vh;
  display: flex;
  flex-flow: row;
  justify-content: center;
  align-items: center;
}
.clock-inner {
  width: 100%;
  display: flex;
  justify-content: center;
}
p {
  margin: 0;
  background-color: #999;
  text-align: center;
  flex-basis: 180px;
  span:first-child {
    height: 180px;
    width: 100%;
    display: table;
    & > * {
      display: table-cell;
      vertical-align: middle;
    }
  }
}
.animator {
  animation: 1s linear rotate infinite;
  transform-origin: 50% 52.5%;
}
.hours {
  span:first-child {
    font-size: 125%;
  }
  .animator {
    animation-duration: 43200s;
  }
}
.minutes {
  span:first-child {
    font-size: 100%;
  }
  .animator {
    animation-duration: 3600s;
  }
}
.seconds {
  span:first-child {
    font-size: 80%;
    animation-duration: 60s;
  }
}
span {
  bottom: 0;
  display: block;
  font-size: 32px;
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to {   transform: rotate(359.999deg); }
}

@media (max-width: 512px) {
  .clock-inner {
    flex-flow: column;
  }
}
              
            
!

JS

              
                $(document).ready(() => {
  var animInit = false;   // this decides whether the animation delays will still need to be set
  updateTimeFields();     // run the update time function initially
  window.setInterval(updateTimeFields, 1000);   // run the update time function again every second
  
  function updateTimeFields() {
    let date = new Date();    // get the current time
    // force 12-hour time
    let hours = date.getHours() > 12 ? date.getHours() - 12 : (date.getHours() === 0 ? 12 : date.getHours());
    // including leading zeros if necessary
    let mins = date.getMinutes() < 10 ? "0" + date.getMinutes().toString() : date.getMinutes();
    let sec = date.getSeconds() < 10 ? "0" + date.getSeconds().toString() : date.getSeconds();
    // update text fields
    $("#hr").text(hours);
    $("#min").text(mins);
    $("#sec").text(sec);
    
    // if this is the first iteration of the function, set negative animation delays to rotate individual clock elements appropriately
    if (!animInit) {
      // hours must compare against the number of seconds elapsed in this 12 hour period
      $(".hours .animator").css(
        "animation-delay", (
          (-1 * (
            (hours * 60 * 60) + 
            (mins * 60) + 
            (sec)
          )) + 's'
        )
      );
      
      // minutes compares against the number of seconds elapsed this hour
      $(".minutes .animator").css(
        "animation-delay", (
          (-1 * (
            (mins * 60) + 
            (sec)
          )) + 's'
        )
      );
      
      // seconds can compare directly against the current seconds
      $(".seconds .animator").css(
        "animation-delay", (
          (-1 * (
            sec
          )) + 's'
        )
      );
      animInit = true;
    }
  }
})
              
            
!
999px

Console