Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

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?

#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 to document.

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"); 
    }    
});