Advertisement
Guest User

Untitled

a guest
Sep 29th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function Counter(ms,accuracy){
  3.     var duration = ms;
  4.     var progress = 0;
  5.     var accuracy = accuracy || 100; //100ms update default
  6.    
  7.    
  8.     var interval = setInterval(tick(), accuracy);
  9.    
  10.     function tick(){
  11.         progress += accuracy;
  12.          console.log(progress);
  13.         if (progress >= duration){
  14.             window.clearInterval(interval);
  15.             console.log("Timer finished");
  16.         }
  17.        
  18.     }
  19.  
  20. }
  21.  
  22.  
  23. var x = new Counter(20000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement