Return to Snippet

Revision: 63370
at May 2, 2013 01:34 by scorpayllc


Initial Code
<html>
<head>
<title>Landing Page</title>
<style>
.timer {
	color:red;
	border:none;
	font-family:verdana;
	font-size:16pt;
	font-weight:bold;
	border-right-color:#FFFFFF
}
</style>
</head>

<script>
// Random Countdown Timer Script Sporadic Effect Version, by http://ctrtard.com
var timer;
function startCount()
{
	timer = setInterval(count, 100); // 200 = 200ms delay between counter changes. Lower num = faster, Bigger = slower.
}
function count()
{
	var do_wait = Math.ceil(4*Math.random()); // for "sporadic effect", we generate a random number between 1 and 4
	if (do_wait == 4) { // now, we only decrement the counter if the random number = 4 --- otherwise we don't do anything.
		var rand_no = Math.ceil(9*Math.random()); // 9 = random decrement amount. Counter will decrease anywhere from 1 - 9.
		var el = document.getElementById('counter');
		var currentNumber =	parseFloat(el.innerHTML);
		var newNumber = currentNumber - rand_no;
		if (newNumber > 0) {
			el.innerHTML = newNumber;
		} else {
			el.innerHTML = "Sold Out";  // This message is displayed when the counter reaches zero.
		}
	}
}
</script>




<body onLoad="startCount();">

<span class="timer"><span id="counter">431</span></span>

</body>

</html>

Initial URL


Initial Description


Initial Title
"Sold Out" Javascript Countdown + Sporadic Effect

Initial Tags


Initial Language
JavaScript