CSS clock with connected hands
by OxC0FFEE
HTML
<div class="outercontainer">
<div class="container">
<div class="clock">
<div class="hands">
<div id="hourcontainer"><div class="hour"><div class="hand"><span class="face">HH</span></div><div id="minutecontainer"><div class="minute"><div class="hand"><span class="face">MM</span></div><div id="secondcontainer"><div class="second"><div class="hand"><span class="face">SS</span></div></div></div></div></div></div></div>
</div>
</div>
</div>
</div>
CSS
* {
box-sizing: border-box;
}
.outercontainer {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.container {
display: table-cell;
vertical-align: middle;
}
.clock {
margin: 2em auto 0 auto;
width: 100%;
}
.hands {
transform: rotate(-90deg);
}
#hourcontainer, #minutecontainer, #secondcontainer {
transform-origin: 0%;
/* outline: 1px solid black; */
display: inline-block;
float: right;
}
#hourcontainer {
transform-origin: -1em;
}
#minutecontainer {
transform-origin: -0.75em;
}
#secondcontainer {
transform-origin: -0.5em;
}
.hour, .minute, .second {
width: 10em;
display: inline-block;
float: right;
}
.hour span, .minute span, .second span {
display: inline-block;
padding: 0 0.5em;
font-family: "Myriad Pro", Myriad, Trebuchet MS, Arial, Sans-Serif;
}
.hand {
width: 10em;
background-color: black;
float: left;
border-radius: 1em;
border: 1px solid black;
}
.minute .hand {
background-color: red;
}
.second .hand {
background-color: blue;
}
.hour, .minute, .second {
/* outline: 1px solid green; */
}
.hour {
width: 30em;
animation: rotation 43200s infinite linear; /* 43200 */
transform-origin: 1em;
}
.hour span {
line-height: 2em;
color: white;
}
.minute {
width: 20em;
animation: rotation 3600s infinite linear; /* 3600 */
transform-origin: 0.75em;
position: relative;
left: -1.5em;
margin-top: 0.25em;
}
.minute span {
line-height: 1.5em;
color: white;
}
.second {
width: 10em;
/* animation: rotation 60s infinite linear; /* smooth */
animation: rotation 60s steps(60, end) 0s infinite; /* stepped */transform-origin: 0.5em;
position: relative;
left: -1em;
margin-top: 0.25em;
}
.second span {
line-height: 1em;
color: white;
}
@keyframes rotation {
from {transform:...
JavaScript
var currentTime = new Date ();
var currentHours = currentTime.getHours();
var currentMinutes = currentTime.getMinutes();
var currentSeconds = currentTime.getSeconds();
/* compensate for nested rotation - minutes/seconds not quite right? */
$("#hourcontainer").css("-webkit-transform", "rotate("+ currentHours*30 +"deg)");
$("#minutecontainer").css("-webkit-transform", "rotate("+ (-currentHours*30 + currentMinutes*6) +"deg)");
$("#secondcontainer").css("-webkit-transform", "rotate("+ (-(currentMinutes*6) + currentSeconds*6) +"deg)");
$("#hourcontainer").css("-moz-transform", "rotate("+ currentHours*30 +"deg)");
$("#minutecontainer").css("-moz-transform", "rotate("+ (-currentHours*30 + currentMinutes*6) +"deg)");
$("#secondcontainer").css("-moz-transform", "rotate("+ (-(currentMinutes*6) + currentSeconds*6) +"deg)");
$("#hourcontainer").css("-transform", "rotate("+ currentHours*30 +"deg)");
$("#minutecontainer").css("-transform", "rotate("+ (-currentHours*30 + currentMinutes*6) +"deg)");
$("#secondcontainer").css("-transform", "rotate("+ (-(currentMinutes*6) + currentSeconds*6) +"deg)");
setInterval ( function() {
var currentTime = new Date ( );
var currentHours = currentTime.getHours ( );
var currentMinutes = currentTime.getMinutes ( );
var currentSeconds = currentTime.getSeconds ( );
// Pad the minutes and seconds with leading zeros, if required
currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
// Choose either "AM" or "PM" as appropriate
var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";
// Convert the hours component to 12-hour format if needed
currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
// Convert an hours component of "0" to "12"
currentHours = ( currentHours == 0 ) ? 12 : currentHours;
// set initial time
$(".hour...