"Sold Out" Javascript Countdown + Sporadic Effect


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <html>
  2. <head>
  3. <title>Landing Page</title>
  4. <style>
  5. .timer {
  6. color:red;
  7. border:none;
  8. font-family:verdana;
  9. font-size:16pt;
  10. font-weight:bold;
  11. border-right-color:#FFFFFF
  12. }
  13. </style>
  14. </head>
  15.  
  16. <script>
  17. // Random Countdown Timer Script Sporadic Effect Version, by http://ctrtard.com
  18. var timer;
  19. function startCount()
  20. {
  21. timer = setInterval(count, 100); // 200 = 200ms delay between counter changes. Lower num = faster, Bigger = slower.
  22. }
  23. function count()
  24. {
  25. var do_wait = Math.ceil(4*Math.random()); // for "sporadic effect", we generate a random number between 1 and 4
  26. if (do_wait == 4) { // now, we only decrement the counter if the random number = 4 --- otherwise we don't do anything.
  27. var rand_no = Math.ceil(9*Math.random()); // 9 = random decrement amount. Counter will decrease anywhere from 1 - 9.
  28. var el = document.getElementById('counter');
  29. var currentNumber = parseFloat(el.innerHTML);
  30. var newNumber = currentNumber - rand_no;
  31. if (newNumber > 0) {
  32. el.innerHTML = newNumber;
  33. } else {
  34. el.innerHTML = "Sold Out"; // This message is displayed when the counter reaches zero.
  35. }
  36. }
  37. }
  38. </script>
  39.  
  40.  
  41.  
  42.  
  43. <body onLoad="startCount();">
  44.  
  45. <span class="timer"><span id="counter">431</span></span>
  46.  
  47. </body>
  48.  
  49. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.