function countdown


SUBMITTED BY: Guest

DATE: Jan. 5, 2014, 2:58 a.m.

FORMAT: Text only

SIZE: 659 Bytes

HITS: 1130

  1. function Countdown(options) {
  2. var timer,
  3. instance = this,
  4. seconds = options.seconds || 10,
  5. updateStatus = options.onUpdateStatus || function () {},
  6. counterEnd = options.onCounterEnd || function () {};
  7. function decrementCounter() {
  8. updateStatus(seconds);
  9. if (seconds === 0) {
  10. counterEnd();
  11. instance.stop();
  12. }
  13. seconds--;
  14. }
  15. this.start = function () {
  16. clearInterval(timer);
  17. timer = 0;
  18. seconds = options.seconds;
  19. timer = setInterval(decrementCounter, 1000);
  20. };
  21. this.stop = function () {
  22. clearInterval(timer);
  23. };
  24. }

comments powered by Disqus