Answer the question
In order to leave comments, you need to log in
How to show spinner only on long loading?
All SPA pages have a spinner, but sometimes the data comes quickly and the spinner is just annoying. How to make it display only about loading data more than n-time.
Answer the question
In order to leave comments, you need to log in
Show it after a certain period of time. For example, after two seconds.
setTimeout(function() {
initSpinner();
}, 2000);
You won't be able to calculate in advance, unless you are Vanga: D
Implement simple logic - show the spinner after 300 ms, if no answer has been received during this time.
If the answer comes later, and the spinner is already displayed, then we make a forced delay so that the spinner is displayed for at least N ms.
0ms - sent a request
300ms - no response, turn on the loader
350ms - response received, the loader is active, the minimum display time of the loader is 400ms, we postpone the processing of the received data by 400 - (350-300) = 350ms
700ms - hide the loader, process the data (dump it into the scope etc)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question