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

              
                <div id="container">
  <img id="face" src="https://i.imgur.com/qi8uJO9.png">
  <img id="hour" class="hand" src="https://i.imgur.com/DAoHqmi.png">
  <img id="minute" class="hand" src="https://i.imgur.com/GQ8J45o.png">
  <img id="second" class="hand" src="https://i.imgur.com/elHp6bt.png">
</div>
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 0;
  max-width: 400px;
}

#container {
  position: relative;
  overflow: hidden;
}

img {
  max-width: 100%;
  display: block;
}

.hand {
  position: absolute;
  top: 0;
  left: 0;
}

#second {
  -webkit-animation: seconds 60s steps(60, end) infinite;
  animation: seconds 60s steps(60, end) infinite;
}

#minute {
  -webkit-animation: minutes 3600s infinite linear;
  animation: minutes 3600s infinite linear;
}

#hour {
  -webkit-animation: hours 43200s infinite linear;
  animation: hours 43200s infinite linear;
}

              
            
!

JS

              
                //get current time
var date = new Date();
var seconds = date.getSeconds();
var minutes = date.getMinutes();
var hours = date.getHours();
if (hours > 12) {
  hours = hours - 12;
}

//calculate initial rotations
var secondDegs = seconds * 6;
var minuteDegs = minutes * 6 + seconds / 10;
var hourDegs = hours * 30 + minutes / 2 + seconds / 120;

//calculate end rotations
var secondEnd = secondDegs + 360;
var minuteEnd = minuteDegs + 360;
var hourEnd = hourDegs + 360;

//set initial rotations
$("#second").css("transform", "rotate(" + secondDegs + "deg)");
$("#minute").css("transform", "rotate(" + minuteDegs + "deg)");
$("#hour").css("transform", "rotate(" + hourDegs + "deg)");

//create css keyframe animation syntax
var styleHtml =
  '<style type="text/css">' +
  "@-webkit-keyframes seconds {" +
  "0% { transform: rotate(" +
  secondDegs +
  "deg); }" +
  "100% { transform: rotate(" +
  secondEnd +
  "deg); }" +
  "}" +
  "@keyframes seconds {" +
  "0% { transform: rotate(" +
  secondDegs +
  "deg); }" +
  "100% { transform: rotate(" +
  secondEnd +
  "deg); }" +
  "}" +
  "@-webkit-keyframes minutes {" +
  "0% { transform: rotate(" +
  minuteDegs +
  "deg); }" +
  "100% { transform: rotate(" +
  minuteEnd +
  "deg); }" +
  "}" +
  "@keyframes minutes {" +
  "0% { transform: rotate(" +
  minuteDegs +
  "deg); }" +
  "100% { transform: rotate(" +
  minuteEnd +
  "deg); }" +
  "}" +
  "@-webkit-keyframes hours {" +
  "0% { transform: rotate(" +
  hourDegs +
  "deg); }" +
  "100% { transform: rotate(" +
  hourEnd +
  "deg); }" +
  "}" +
  "@keyframes hours {" +
  "0% { transform: rotate(" +
  hourDegs +
  "deg); }" +
  "100% { transform: rotate(" +
  hourEnd +
  "deg); }" +
  "}" +
  "</style>";

//append CSS rules to head
$("head").append(styleHtml);

              
            
!
999px

Console