"Sold Out" Javascript Random Countdown Script


/ 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, by http://ctrtard.com
  18. var timer;
  19. function startCount()
  20. {
  21. timer = setInterval(count,200); // 200 = 200ms delay between counter changes. Lower num = faster, Bigger = slower.
  22. }
  23. function count()
  24. {
  25. var rand_no = Math.ceil(9*Math.random()); // 9 = random decrement amount. Counter will decrease anywhere from 1 - 9.
  26. var el = document.getElementById('counter');
  27. var currentNumber = parseFloat(el.innerHTML);
  28. var newNumber = currentNumber - rand_no;
  29. if (newNumber > 0) {
  30. el.innerHTML = newNumber;
  31. } else {
  32. el.innerHTML = "Sold Out"; // This message is displayed when the counter reaches zero.
  33. }
  34. }
  35. </script>
  36.  
  37. <body onLoad="startCount();">
  38.  
  39. <span class="timer"><span id="counter">431</span></span>
  40.  
  41. </body>
  42.  
  43. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.