Clock
It's a clock.
by Josh Pullen
HTML
<div id="time"></div>
CSS
@import url(http://fonts.googleapis.com/css?family=Open+Sans);
#time {
font-size:300px;
height:300xpx;
width:100%;
position:absolute;
top:50%;
text-align:center;
}
#time::selection {
background:red;
}
body {
overflow:hidden;
font-family:'Open Sans', sans-serif;
margin:0px;
padding:0px;
}
JavaScript
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
m = checkTime(m);
h = checkHour(h);
document.getElementById('time').innerHTML = h + ":" + m;
var t = setTimeout(function () {
startTime()
}, 500);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i
}; // add zero in front of numbers < 10
return i;
}
function checkHour(i) {
return i % 12;
}
window.onload = startTime();
var moveIt = function () {
var halfObjectHeight = ($('#time').height() / 2);
$('#time').css({
'margin-top': -halfObjectHeight + "px"
});
};
window.setInterval(function () {
moveIt();
}, 0);
$(window).resize(moveIt);
moveIt();