Created
June 27, 2011 08:14
-
-
Save keithbloom/1048488 to your computer and use it in GitHub Desktop.
so_6469804
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" language="JavaScript"> | |
function addCommas(nStr) | |
{ | |
nStr += ''; | |
x = nStr.split('.'); | |
x1 = x[0]; | |
x2 = x.length > 1 ? '.' + x[1] : ''; | |
var rgx = /(\d+)(\d{3})/; | |
while (rgx.test(x1)) { | |
x1 = x1.replace(rgx, '$1' + ',' + '$2'); | |
} | |
return x1 + x2; | |
} | |
function doWork() { | |
document.getElementById('counter').innerHTML = 'Test'; | |
} | |
var START_DATE = new Date("July 1, 2007 13:30:00"); // put in the starting date here | |
var INTERVAL = 3; // in seconds | |
var INCREMENT = 1; // increase per tick | |
var START_VALUE = 0; // initial value when it's the start date | |
var count = 0; | |
window.onload = function() | |
{ | |
var msInterval = INTERVAL * 1000; | |
var now = new Date(); | |
count = parseInt((now - START_DATE)/msInterval) * INCREMENT + START_VALUE; | |
document.getElementById('counter').innerHTML = addCommas(count); | |
setInterval("count += INCREMENT; document.getElementById('counter').innerHTML = addCommas(count);", msInterval); | |
document.getElementById('clicker').addEventListener('click', doWork, false); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="counter"></div> | |
<p id="clicker">Click me</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment