Posted By

warbear on 09/22/12


Tagged

alert countDown


Versions (?)

CountDown with Thresh-holds


 / Published in: JavaScript
 

var seconds: set this to what you want the count down to start at. var alarm1 etc: set these values to your thresh hold values

in either a style tag, or css file, define how you want the appearance to be with the tags of:

alert1 alert2 alert3.

  gets placed where you want the counter.

Enjoy.

  1. var seconds = 70;
  2. var alarm1 = 60;
  3. var alarm2 = 30;
  4. var alarm3 = 10;
  5.  
  6. var int = window.setInterval("countdown()",1000);
  7.  
  8. function countdown(){
  9. seconds--;
  10. var count = document.getElementById("count");
  11. count.innerHTML = seconds;
  12. if (seconds <= alarm1) { count.innerHTML = "<span id=alert1>" + seconds + "</span>"; }
  13. if (seconds <= alarm2) { count.innerHTML = "<span id=alert2>" + seconds + "</span>"; }
  14. if (seconds <= alarm3) { count.innerHTML = "<span id=alert3>" + seconds + "</span>"; }
  15. if (seconds == 0){
  16. window.clearInterval(int);
  17. // window.location = "location";
  18. count.innerHTML = "Finished!";
  19. }
  20. }

Report this snippet  

You need to login to post a comment.