But then, the animation time will be irrespective of the actual loading time, that is, 5 seconds fixed. What if it takes longer or shorter time to load?
You're right. In that case all you need to do is store the timer id which is returned by the setTimeout in a global variable. Later if the response comes earlier than 5 secs, you just need to clear out the timer by adding one line in hideLoading()
clearTimeout( timerId ) // This will clear the timer and the .display class is anyway removed
But in case of late response, you can get rid of the setTimeout logic altogether and it'll work fine
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
But then, the animation time will be irrespective of the actual loading time, that is, 5 seconds fixed. What if it takes longer or shorter time to load?
You're right. In that case all you need to do is store the timer id which is returned by the
setTimeout
in a global variable. Later if the response comes earlier than 5 secs, you just need to clear out the timer by adding one line inhideLoading()
But in case of late response, you can get rid of the
setTimeout
logic altogether and it'll work fine