CSS
body {
background: #F00;
-webkit-perspective: 1000;
-moz-perspective: 1000;
perspective: 1000;
font-family: 'Source Sans Pro', sans-serif;
-webkit-transform: scale(0.8, 0.8) translate(0, -20px);
-moz-transform: scale(0.8, 0.8) translate(0, -20px);
transform: scale(0.8, 0.8) translate(0, -20px);
}
.byline {
text-align: center;
margin-top: 100px;
}
.byline a {
text-decoration: none;
cursor: pointer;
}
.clock {
width: 800px;
height: 350px;
border-radius: 10px;
background: #000;
margin: 0px auto;
margin-top: 100px;
text-align: center;
padding-top: 30px;
color: #2df;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.clock2 {
-webkit-transform: rotateX(180deg);
transform: rotateX(180deg);
}
.clock .off {
-webkit-transition: all 0.2s linear;
-moz-transition: all 0.2s linear;
transition: all 0.2s linear;
opacity: 0.2;
}
.clock .fadeout {
background: linear-gradient(to bottom, rgba(255,255,255,1), rgba(255,255,255, 0.8));
background-image: -webkit-linear-gradient(top, rgba(255,255,255,1), rgba(255,255,255, 0.8));
position: absolute;
top: 0px;
left: 0px;
width: 700px;
height: 350px;
}
.clock ul {
margin: 0;
padding: 0;
position: relative;
}
.clock ul li {
list-style: none;
display: inline-block;
position: relative;
top: 30px;
margin: 0;
padding: 0;
width: 120px;
height: 200px;
}
.clock ul li.ampm {
position: absolute;
bottom: 160px;
right: 50px;
height: 10px;
width: 30px;
}
.clock ul li.ampm.pm {
top: 208px;
}
.clock ul li.separator {
font-size: 100px;
height: 150px;
width: 40px;
position: relative;
top: -42px;
}
.clock ul li.digit {
font-size: 200px;
}
.clock .bar {
position: absolute;
border-radius: 10px;
border: 8px solid red;
background: red;
-webkit-transition: all 0.2s linear;
-moz-transition: all 0.2s linear;
transition: all 0.2s linear;
}
.clock .bar0 { left: 20px; top: 5px;...
JavaScript
var DIGIT_BITMAP = [
[1, 1, 1, 0, 1, 1, 1], // 0
[0, 0, 1, 0, 0, 1, 0],
[1, 0, 1, 1, 1, 0, 1], // 2
[1, 0, 1, 1, 0, 1, 1],
[0, 1, 1, 1, 0, 1, 0], // 4
[1, 1, 0, 1, 0, 1, 1],
[1, 1, 0, 1, 1, 1, 1], // 6
[1, 0, 1, 0, 0, 1, 0],
[1, 1, 1, 1, 1, 1, 1], // 8
[1, 1, 1, 1, 0, 1, 1]
];
function $q(selector, context) {
return (context || document).querySelector(selector);
}
function setDigit(context, which, value) {
var $digit = $q(".digit" + which, context);
for (var bar = 0; bar <= 6; bar++) {
var $bar = $q(".bar" + bar, $digit);
if (DIGIT_BITMAP[value][bar] === 0) {
addClass($bar, "off");
} else {
removeClass($bar, "off");
}
}
}
function addClass(element, klass) {
if (!hasClass(element, klass)) {
element.className = (element.className || '') + " " + klass;
}
}
function removeClass(element, klass) {
if (hasClass(element, klass)) {
// Pad out w/ delimiters to isolate classname.
element.className = (" " + (element.className || '') + " ").
replace(" " + klass + " ", "").
replace(/^\s+/, '').
replace(/\s+$/, '');
}
}
function hasClass(element, klass) {
var classes = (element.className || '').split(/\s/);
for (var i = 0; i < classes.length; i++) {
if (classes[i] === klass) {
return true;
}
}
return false;
}
function update(context) {
var rnd = Math.floor(Math.random() * 10);
setDigit(context, 1, rnd);
rnd = Math.floor(Math.random() * 10);
setDigit(context, 2, rnd);
rnd = Math.floor(Math.random() * 10);
setDigit(context, 3, rnd);
rnd = Math.floor(Math.random() * 10);
setDigit(context, 4, rnd);
rnd = Math.floor(Math.random() * 10);
setDigit(context, 5, rnd);
rnd = Math.floor(Math.random() * 10);
setDigit(context, 6, rnd);
}
function updateAll() {
update($q(".clock1"));
}
var $clocks = $q(".clocks"),
$stopMoving = $q("#stop-moving");
setInterval(updateAll, 2000);
updateAll();