Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <body>
  <div id="clock">
    <img id="clock_face" src="https://i.imgur.com/ZkM3iQs.png" alt="clock face" />
    <img id="seconds_hand" src="https://i.imgur.com/CpDgUSW.png" alt="seconds hand" />
    <img id="minutes_hand" src="https://i.imgur.com/wTsWL3f.png" alt="minutes hand" />
    <img id="hours_hand" src="https://i.imgur.com/Y31WhbA.png" alt="hours hand" />
  </div>
  <div id="badges">
    <table id="badges_table">
      <tr id="badge_states">
        <th class="state disabled">Disabled or Blank</th>
        <th class="state disabled">Enabled</th>
      </tr>
      <tr id="blank_badge" class="one_o_clock">
        <td class="badge blank"><img src="https://i.imgur.com/EEx455V.png" alt="Blank Badge" /></td>
      </tr>
      <tr id="discover_minutes_badge" class="two_o_clock">
        <td id="discover_minutes_badge_disabled" class="badge disabled">
          <img src="https://i.imgur.com/3dvNeLI.png" alt="Discover Minutes Badge - Disabled" />
          <p class="description">Discover Minutes Badge - Allow the minutes hand to do its thing.</p>
        </td>
        <td id="discover_minutes_badge_enabled" class="badge enabled">
          <img src="https://i.imgur.com/Jhi22Qa.png" alt="Discover Minutes Badge - Enabled" />
          <p class="description">Discover Minutes Badge - You have uncovered the mystery of the minutes hand: It moves once a minute.</p>
        </td>
      </tr>
      <tr id="blank_badge" class="three_o_clock">
        <td class="badge blank"><img src="https://i.imgur.com/EEx455V.png" alt="Blank Badge" /></td>
      </tr>
      <tr id="blank_badge" class="four_o_clock">
        <td class="badge blank"><img src="https://i.imgur.com/EEx455V.png" alt="Blank Badge" /></td>
      </tr>
      <tr id="blank_badge" class="five_o_clock">
        <td class="badge blank"><img src="https://i.imgur.com/EEx455V.png" alt="Blank Badge" /></td>
      </tr>
      <tr id="discover_seconds_badge" class="six_o_clock">
        <td id="discover_seconds_badge_disabled" class="badge disabled">
          <img src="https://i.imgur.com/Jdhnotg.png" alt="Discover Seconds Badge - Disabled" />
          <p class="description">Discover Seconds Badge - Allow the seconds hand to do its thing.</p>
        </td>
        <td id="discover_seconds_badge_enabled" class="badge enabled">
          <img src="https://i.imgur.com/Y6swcwL.png" alt="Discover Seconds Badge - Enabled" />
          <p class="description">Discover Seconds Badge - You have uncovered the mystery of the seconds hand: It moves once a second.</p>
        </td>
      </tr>
      <tr id="blank_badge" class="seven_o_clock">
        <td class="badge blank"><img src="https://i.imgur.com/EEx455V.png" alt="Blank Badge" /></td>
      </tr>
      <tr id="blank_badge" class="eight_o_clock">
        <td class="badge blank"><img src="https://i.imgur.com/EEx455V.png" alt="Blank Badge" /></td>
      </tr>
      <tr id="blank_badge" class="nine_o_clock">
        <td class="badge blank"><img src="https://i.imgur.com/EEx455V.png" alt="Blank Badge" /></td>
      </tr>
      <tr id="discover_hours_badge" class="ten_o_clock">
        <td id="discover_hours_badge_disabled" class="badge disabled">
          <img src="https://i.imgur.com/H6C2FgT.png" alt="Discover Hours Badge - Disabled" />
          <p class="description">Discover Hours Badge - Allow the hours hand to do its thing.</p>
        </td>
        <td id="discover_hours_badge_enabled" class="badge enabled">
          <img src="https://i.imgur.com/vrPB2EU.png" alt="Discover Hours Badge - Enabled" />
          <p class="description">Discover Hours Badge - You have uncovered the mystery of the hours hand: It moves once an hour.</p>
        </td>
      </tr>
      <tr id="blank_badge" class="eleven_o_clock">
        <td class="badge blank"><img src="https://i.imgur.com/EEx455V.png" alt="Blank Badge" /></td>
      </tr>
      <tr id="blank_badge" class="twelve_o_clock">
        <td class="badge blank"><img src="https://i.imgur.com/EEx455V.png" alt="Blank Badge" /></td>
      </tr>
    </table>
  </div>
  <div id="alertText">
    <p>You Earned<br>a Badge!!!</p>
  </div>
</body>

              
            
!

CSS

              
                /*************
* Clock
************/
#clock {
  left: 0px;
  height: 512px;
  margin: 0;
  padding: 0;
  position: absolute;
  top: 0px;
  width: 512px;
}

#clock_face {
  border: 4px solid black;
  border-radius: 5%;
  height: 504px;  
  position: absolute;
  width: 504px;
}

#seconds_hand, #minutes_hand, #hours_hand {
  height: 512px;
  left: 0px;
  position: absolute;
  top: 0px;
  width: 512px;
}

/*************
* Badges
************/
table {
  table-style: none;
  margin: 0;
  padding: 0;
}

#badge_states {
  display: none;
}

.badge {
  margin: 0;
  padding: 0;
}

.badge.enabled {
  display: none;
}

.badge.blank, .badge.disabled {
  display: block;
}

.badge.blank {
  opacity: 0.25;
}

.description {
  position: relative;
  display: none;
  border: 1px solid black;
  border-radius: 5px;
  width: 128px;
  left: -32px;
  top: -76px;
  text-align: center;
  margin: 0;
  padding: 0;
}

.badge.disabled .description {
  background-color: rgba(192,192,192,0.95);  
}

.badge.enabled .description {
  background-color: rgba(192,255,192,0.95);
}

.badge.disabled:hover .description, .badge.enabled:hover .description {
  display: block;
}

.one_o_clock {
  position: absolute;
  left: 312px;
  top: 72px;
}

.two_o_clock {
  position: absolute;
  left: 376px;
  top: 136px;
}

.three_o_clock {
  position: absolute;
  left: 400px;
  top: 224px;
}

.four_o_clock {
  position: absolute;
  left: 376px;
  top: 312px;
}

.five_o_clock {
  position: absolute;
  left: 312px;
  top: 376px;
}

.six_o_clock {
  position: absolute;
  left: 224px;
  top: 400px;
}

.seven_o_clock {
  position: absolute;
  left: 136px;
  top: 376px;
}

.eight_o_clock {
  position: absolute;
  left: 72px;
  top: 312px;
}

.nine_o_clock {
  position: absolute;
  left: 48px;
  top: 224px;
}

.ten_o_clock {
  position: absolute;
  left: 72px;
  top: 136px;
}

.eleven_o_clock {
  position: absolute;
  left: 136px;
  top: 72px;
}

.twelve_o_clock {
  position: absolute;
  left: 224px;
  top: 48px;
}

/************
* Alerts
************/

#alertText {
  color: transparent;
  font-size: 0.5em;
  position: absolute;
  text-align: center;
  top: 128px;
  width: 512px;
}

@-webkit-keyframes showAlertText {
  50% {
    color: limegreen;
    font-size: 2.5em;
  }
  
  100% {
    font-size: 5em;
  }
}
              
            
!

JS

              
                var lastSeconds = -1;
var lastMinutes = -1;
var lastHours = -1;
var discoverSecondsBadge = false;
var discoverMinutesBadge = false;
var discoverHoursBadge = false;

var updateClockInterval = setInterval(function() {updateClock()}, 1000);

function updateClock() {
  var date = new Date();

  var seconds = date.getSeconds();
  if (seconds != lastSeconds) {
    drawSecondsHand(seconds);
    if ((discoverSecondsBadge == false) && (seconds != lastSeconds) && (lastSeconds != -1)) {
      discoverSecondsBadge = true;
      document.getElementById("discover_seconds_badge_disabled").style.display = "none";
      document.getElementById("discover_seconds_badge_enabled").style.display = "block";
      showAlertText();
    }
    lastSeconds = seconds;
  }  

  var minutes = date.getMinutes();
  if (minutes != lastMinutes) {
    drawMinutesHand(minutes);  
    if ((discoverMinutesBadge == false) && (minutes != lastMinutes) && (lastMinutes != -1)) {
      discoverMinutesBadge = true;
      document.getElementById("discover_minutes_badge_disabled").style.display = "none";
      document.getElementById("discover_minutes_badge_enabled").style.display = "block";
      showAlertText();
    }
    lastMinutes = minutes;
  }  

  var hours = date.getHours();
  if (hours != lastHours) {
    drawHoursHand(hours);
    if ((discoverHoursBadge == false) && (hours != lastHours) && (lastHours != -1)) {
      discoverHoursBadge = true;
      document.getElementById("discover_hours_badge_disabled").style.display = "none";
      document.getElementById("discover_hours_badge_enabled").style.display = "block";
      showAlertText();
    }
    lastHours = hours;
  }
}

function drawSecondsHand(seconds) {
  seconds = seconds % 60;
  var angle = seconds * 360 / 60;
  var styleTransform = "rotate(" + angle + "deg)";
  var secondsHand = document.getElementById("seconds_hand");
  if (secondsHand != null) {
    secondsHand.style.WebkitTransform = styleTransform;
  }
}

function drawMinutesHand(minutes) {
  minutes = minutes % 60;
  var angle = minutes * 360 / 60;
  var styleTransform = "rotate(" + angle + "deg)";
  var minutesHand = document.getElementById("minutes_hand");
  if (minutesHand != null) {
    minutesHand.style.WebkitTransform = styleTransform;
  }
}

function drawHoursHand(hours) {
  hours = hours % 12;
  var angle = hours * 360 / 12;
  var styleTransform = "rotate(" + angle + "deg)";
  var hoursHand = document.getElementById("hours_hand");
  if (hoursHand != null) {
    hoursHand.style.WebkitTransform = styleTransform;
  }
}

function showAlertText() {
  var alertText = document.getElementById("alertText");
  if (alertText != null) {
    var styleAnimation = "showAlertText 5s linear";
    alertText.style.WebkitAnimation = styleAnimation;
  }
}
              
            
!
999px

Console