views:

808

answers:

2

Hi, I'm trying to do something like boxy or facebox or lightbox...and so on. The only problem is that I don't know how to preload the page that is loaded into the box via load() method.

It should work like this:

  1. It pops the box
  2. Loading animation is added
  3. When the page is loaded the animation disappears

So i need to know when the page is loaded to remove the animation.

+1  A: 

If I understand you correctly, you are saying that because a page on your site will take a while to load, you would like a friendly loading message to show immediately and disappear once the page is loaded.

The trick to this is not downloading much when the page first loads. Just the loading message and some JavaScript.

What makes this work is that in your $(document).ready() function you'll use AJAX to get the slow data. Once the AJAX query returns, use JS to populate the page with the data and then turn off the loading message.

Michael La Voie
hmm...actually that's my question, how can i "see" when it's ok to remove the loading animation?something like this it's enough?$(selector).load('page.php',function(){ $('.animation').remove();});
kmunky
+2  A: 
var function_for_display_animation = function(){
   //display animation
}
var function_for_remove_animation = function(){
   //remove animation
}

function_for_display_animation();
$(selector).load('page.php',function_for_remove_animation);

or:

$().ajaxSend(function(evt, request, settings){
    //start animation
});

$().ajaxComplete(function(event,request, settings){
    //end animation
 });

$(selector).load('page.php', function(){
    //work
});
andres descalzo
thanks for your answer, so the callback function is the key
kmunky