Home › Forums › CSS › Center the loading .gif in the middle of the screen? › Reply To: Center the loading .gif in the middle of the screen?
December 1, 2017 at 1:34 pm
#263222
ugultopu
Participant
The fiddle given by @TylerNYC is perfect. However:
As of jQuery 1.9, all the handlers for the jQuery global Ajax events, including those added with the
.ajaxStart()
method, must be attached todocument
.
Hence, you need to change the ajaxStart()
and ajaxStop()
part as follows:
$(document).on({
// When ajaxStart is fired, add 'loading' to body class
ajaxStart: function() {
$('body').addClass("loading");
},
// When ajaxStop is fired, rmeove 'loading' from body class
ajaxStop: function() {
$('body').removeClass("loading");
}
});