Posted By

LucasRinaldi on 08/11/12


Tagged


Versions (?)

Count with setTimeout


 / Published in: JavaScript
 

Just a counter

  1. var count = 0;
  2. var timer;
  3. var timerOn = false;
  4.  
  5. function timedCount() {
  6. count++;
  7. timer = setTimeout(function(){
  8. timedCount()
  9. }, 1000);
  10. }
  11.  
  12. function doTimer() {
  13. if (!timerOn) {
  14. timerOn = true;
  15. timedCount();
  16. }
  17. }
  18.  
  19. function stopCount() {
  20. clearTimeout(timer);
  21. timerOn = false;
  22. }

Report this snippet  

You need to login to post a comment.