PDA

View Full Version : Helpful JavaScript for Web development



JavaScriptBank
09-08-2010, 08:47 PM
Good and Nice JavaScripts

jsClock: Featured Digital Clock JavaScript

If you're needing a simple digital clock (http://www.javascriptbank.com/en+title=digital clock) that is updating automatically and takes directly the time from the server, also you want to show the time in other count... detail (http://www.javascriptbank.com/jsclock-featured-digital-clock-javascript.html/en//) at JavaScriptBank.com - 2.000+ free JavaScript codes (http://www.javascriptbank.com/)


http://www.javascriptbank.com/javascript.images/time/jsclock-featured-digital-clock-javascript.jpg (http://www.javascriptbank.com/javascript/time/clock-time-date/jsclock-featured-digital-clock-javascript/preview/en/)
Demo: JavaScript jsClock: Featured Digital Clock JavaScript (http://www.javascriptbank.com/jsclock-featured-digital-clock-javascript.html/en/)


How to setup

Step 1: CSS below for styling thescript, place it into HEAD section
CSS

<style type="text/css">
/*
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
*/
.clock{
cursor:pointer;
padding:5px 5px 5px 5px;
margin:5px 0 5px 0;
width:70px;
-webkit-border-bottom-right-radius: 4px;
-webkit-border-bottom-left-radius: 4px;
-webkit-border-top-right-radius: 4px;
-webkit-border-top-left-radius: 4px;
-moz-border-radius-bottomright: 4px;
-moz-border-radius-bottomleft: 4px;
-moz-border-radius-topright: 4px;
-moz-border-radius-topleft: 4px;
text-align:center;
font-weight: bold;
font-family: arial;
}


#clock {
background-color:#000000;
color:#00CC66;
}

#reloj {
background-color:#999999;
color:#FFFFFF;
}


#rellotje {
background-color:#237ab2;
color:#FFFFFF;
}
</style>

Step 2: Use JavaScript code below to setup the script
JavaScript

<script type="text/javascript">
/*
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
*/
function moveClock(idClock,startTime){//move given clock
var timeout=1000;//miliseconds to repeat the function

if ( startTime === undefined ) {//just take the browser time
rightNow = new Date();
hour = rightNow.getHours();
minute = rightNow.getMinutes();
second = rightNow.getSeconds();
}
else{//starttime set
rightNow = startTime.split(':',3);
hour = parseInt(rightNow[0],10);
minute = parseInt(rightNow[1],10);
second = parseInt(rightNow[2],10);
if (second==59){
if (minute==59){
if (hour==23) hour=0;
else hour++;
minute=0;
}else minute++;
second=0;
}else second++;
}

if (minute<10) minute= "0" + minute;
if (second<10) second= "0" + second;

currentTime=hour + ":" + minute + ":" +second;// tim to return
document.getElementById(idClock).innerHTML = currentTime;//tim for the HTML element

//recursivity
if (startTime===undefined) setTimeout("moveClock('"+idClock+"')",timeout);//browser time
else setTimeout("moveClock('"+idClock+"','"+currentTime+"')",timeout);//set time

}
</script>

Step 3: Place HTML below in your BODY section
HTML

Normal clock using browser time:

<div id="clock" class="clock">clock</div>moveClock("clock");<br /><br />
<hr>
Clock using server time:
<div id="reloj" class="clock">reloj</div> moveClock("reloj","< ?php echo date("G:i:s");? >");<br /><br />
<hr>
Clock with manual time:
<div id="rellotje" class="clock">rellotje</div> moveClock("rellotje","23:58:56");<br /><br />
<hr>

<script type='text/javascript'>
moveClock("clock");
moveClock("reloj","2:23:25");
moveClock("rellotje","23:58:56");
</script>







Javascript floating message (http://www.javascriptbank.com/floating-message-scroller.html) - Javascript multi level drop down menu (http://www.javascriptbank.com/javascript-multi-level-drop-down-menu.html) - JavaScript in_array() (http://www.javascriptbank.com/in-array.html)


The Site may provide, or third parties may provide, links to non-JavaScriptBank.com Internet World Wide Web sites or resources. Because JavaScriptBank.com has no control over such sites and resources, you acknowledge and agree that JavaScriptBank.com is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. You further acknowledge and agree that JavaScriptBank.com shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such site or resource.