How to Avoid Delay On First Time Start up of setInterval() Function
Can you please take a look at following code and let me know how I can avoid the delay on only FIRST time of this counting down process?
As you can see the counter works fine but there is a delay on first time starting.
- var sec = 20;
- var timer = setInterval(function() {
- $('#box').text(sec--);
- if (sec == -1) {
- $('#box').css('color','blue');
- clearInterval(timer);
- }
- }, 1000);
Thanks