Digital Clock : Clock « GUI Components « JavaScript DHTML

Home
JavaScript DHTML
1.Ajax Layer
2.Data Type
3.Date Time
4.Development
5.Document
6.Dojo toolkit
7.Event
8.Event onMethod
9.Ext JS
10.Form Control
11.GUI Components
12.HTML
13.Javascript Collections
14.Javascript Objects
15.Javascript Properties
16.jQuery
17.Language Basics
18.Mochkit
19.Mootools
20.Node Operation
21.Object Oriented
22.Page Components
23.Rico
24.Scriptaculous
25.Security
26.SmartClient
27.Style Layout
28.Table
29.Utilities
30.Window Browser
31.YUI Library
JavaScript DHTML » GUI Components » Clock 




Digital Clock

//Digital Clock - http://www.btinternet.com/~kurt.grigg/javascript

/*
Paste this js-link to where ever you want the clock to appear on your page.

<script type="text/javascript" src="digitalclock.js"></script>


Make sure ALL the images are in a folder/directory called exactly "digital" and 
that it and the digitalclock.js file are in the same folder as the web page using 
the script.
*/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<title>Digital Clock</title>

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="content-script-type" content="text/javascript">
<meta http-equiv="content-style-type" content="text/css">


</head>
<body style="background-color:#000000">


<script type="text/javascript">
//Digital Clock - http://www.btinternet.com/~kurt.grigg/javascript


(function(){

var load_pics = [];
var pics = [];
for(i = 0; i < 12; i++){
 load_pics[i= i+".gif";
}              

for(i = 0; i < load_pics.length; i++){
 pics[inew Image();
 pics[i].src = "digital/"+load_pics[i];
}

var idx = document.images.length;
var get_digit_pos = -1;
var digit_pos = [];
var ini_src = [];
var pic_width = [];

for (i = 0; i < 8; i++){
var comma = (i == || i == 5);

if (!comma){ 
 get_digit_pos++;
}

ini_src[i(comma)?"digital/11.gif":"digital/10.gif";
pic_width[i(comma)?9:16;

digit_pos[i= get_digit_pos;

if (digit_pos[i== digit_pos[i-1]){ 
digit_pos[i"";
}

document.write("<img name='"+idx+"digits"+digit_pos[i]+"' src="+ini_src[i]+" height='21' width='"+pic_width[i]+"' alt=''/>")
}

function digitalclock(){
var x = new Date();
var s = x.getSeconds();
var m = x.getMinutes();
var h = x.getHours();
var the_time = ((h < 10)?"0"+h:h)+''+((m < 10)?"0"+m:m)+''+((s < 10)?"0"+s:s);
for (i = 0; i < the_time.length; i++){
document.images[idx+"digits"+i].src = pics[the_time.charAt(i)].src;
}
setTimeout(digitalclock,100);
}
digitalclock();
})();

</script>

</body>
</html>

           
       














digitalclock.zip( 4 k)
Related examples in the same category
1.JavaScript Clock
2.Fancy Clock
3.JavaScript Clock (2)
4.Live image clock
5.Military Clock
6.Standard Clock
7.Animation: clock
8.Simulates a stop watch and displays the elapsed time
9.Calendar with Clock
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.