I have several AJAX calls per page. Some are completely instantaneous, others take a few moments - it all depends on what you clicked.
I want to add a “loader” that will display after X seconds while AJAX will work with the results.
The bootloader works for me:
$(document).ajaxStart(function() {
$("#loader").css("display","block");
}).ajaxSuccess(function() {
$("#loader").css("display","none");
});
These features.
However, it blinks on the screen when the AJAX request is fast ... like in no time. Besides the fact that there is a "blinking", it works great. So, I am trying to delay the change in the css bootloader for a few seconds so that fast results do not cause a "blink".
I tried using setTimeout and jQuery queue for delay. a la:
$(document).ajaxStart(function() {
$("#loader").queue(function(){
$(this).delay(5000);
$(this).css("display","block");
$(this).dequeue();
});
}).ajaxSuccess(function() {
$("#loader").css("display","none");
});
or
$(document).ajaxStart(function() {
setTimeout(function() {
$("#loader").css("display","block");
}, 5000);
}).ajaxSuccess(function() {
$("#loader").css("display","none");
});
( jquery css)
$(document).ajaxStart(function() {
$("#loader").delay(5000).css("display","block")
}).ajaxSuccess(function() {
$("#loader").css("display","none");
});
, , , css ajax ... ( ajax).
, AJAX, 5 ... .
ajaxstart(), X ?
, ajax - onBefore(), , . . ajax 5 , , 10-20 .
"" () ajax. , , ajax. , ajax - setTimeout() ( , ).
css , ajax X ... ?
- AJAX?