Fast price count down on javascript

September 12, 2011 Zend Framework

If you need simple price count down for your web site it’s easy realized on javascript. We can use setInterval() function for this purpose. But if you need fast count down, e.g. decrease high price for 1 cent per step that time interval for setInterval() function will be too small. So we have two trouble with small time interval (less then 200 ms). First is that setInterval() function doesn’t have time to work on each tick. And when you set focuse to another tab of you browser, setInterval() function stops or slows down. It’s the second trouble.
Code below can resolve first problem. It’s much faster then setInterval() function

For solving second problem we need stop countdown, synchronize price value and start count down again when focus return on tab with our count down


Leave a Reply

Your email address will not be published