Thread: Loading Gif
View Single Post
Old 11-22-2012, 04:30 PM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 530 Times in 524 Posts
devnull69 will become famous soon enough
I would

1) pre-load the image so that it is ready before the ajax requests starts
2) show the gif in the #newsContent element instead of the #bo element. This would automatically stop the loading gif by overwriting the #newsContent in the success callback

Code:
$(document).ready(function() {
   var myImage = new Image();
   myImage.onload = function() {
      // here the image has finished loading
      $.ajaxSetup({
         beforeSend: function() {
            $('#newsContent').append(myImage);
         }
      });

      $.ajax({
         ...
         success: function(r) {
            $('#newsContent').html(r);
         },
         ...
      });
   };
   myImage.src = 'pics/loadingAnimation.gif';
});
devnull69 is offline   Reply With Quote