1

All i need to do is this:

I have a football game (all written in pure js) which is 90:00 min.

I need to show users 90 (90:00) min and this should be counted down with animation till 00:00 in 30 seconds time...

What is the best way to approach this? Should i use some animation library?

Dnyanesh
  • 2,265
  • 3
  • 20
  • 17
totothegreat
  • 1,633
  • 4
  • 27
  • 59

2 Answers2

2

You can modify an existing countdown clock like this one, to use a smaller interval of time for countdown callback.

In your case you will need to call the function which handles the countdown 180 times in a second (90mins = 5400sec --> 30/5400=0.0055 --> 5.5ms) so you will have to set the callback interval to around 5.5ms. That sounds like too much calls, so you can optimize it in some way, for example you can count down 10sec in each step and in that case you will have just 18 function calls/sec which sounds more acceptable.

sc3w
  • 1,154
  • 9
  • 21
1

A simple code to count down 3min every second which stops at 0.

var minutesLeft = 90,
interval;

interval = setInterval(function () {
        minutesLeft-=3;
        if(minutesLeft === 0) {
            clearInterval(interval);
        }
    , 1000}
jornare
  • 2,903
  • 19
  • 27
  • If you want to display every minute change you can use this code substracting 1 to minutesLeft every 333ms instead of 3 in 1 second. – Andoni Martín Feb 24 '15 at 08:47