Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
92 lines (72 sloc) 2.33 KB
!!!5
%html
%head
%title
Clock, clock!
%link{:rel=>"stylesheet", :href=>"css/screen.css", :type=>"text/css", :media=>"screen"}
:javascript
function pad(number, length) {
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
}
:javascript
function pad2(number) {
return (number < 10 ? '0' : '') + number
}
:javascript
var d;
var h;
var m;
var s;
function get_time() {
d = new Date();
h = d.getHours();
m = d.getMinutes();
s = d.getSeconds();
display_time();
}
function display_time() {
var timetime;
// determin if it's AM or PM
var meridian='AM';
if(h>12){
h=h-12;
meridian='PM';
}
timetime = ""+pad2(h)+":"+pad2(m)+":"+pad2(s)+" "+meridian;
document.getElementById('clockclock').innerHTML = timetime
// timeout for 10 ms, since this is a recursive loop.
// after 10ms, call `get_time()` which will start the process over again
setTimeout('get_time()', 50);
}
function time_segments() {
for(i=0; i<23; i++) {
x = map(i, 0, 23, 0, window.innerWidth);
currTime = document.createElement("div");
//make a distinction between current time and other times
if(i==h) {
currTime.setAttribute('style', 'position: absolute; top:' + window.innerHeight/2+ 'px;left: ' + x + 'px; font-size: 30px; border-left: dotted 1px; color: #0f9;height: 200px');
} else {
currTime.setAttribute('style', 'position: absolute; top:' + window.innerHeight/2+ 'px;left: ' + x + 'px; font-size: 30px; border-left: dotted 1px; color: #333333;height: 200px');
}
document.body.appendChild(currTime);
}
}
window.onload = function() {
get_time();
//time_segments();
}
/**
window.onresize = function() {
document.body.innerHTML="<div id='clock'></div>";
time_segments();
}
**/
%body
#parent
#container
#clockclock
00:00:00
Something went wrong with that request. Please try again.