Wait until the function is loaded

How can I test jQuery when the javascript function is fully loaded? I would like to use a gif that displays the load, and does the javascript function load and hide it when the function is fully loaded?

+5
source share
3 answers
$(function(){
    $("#loadingGIF").show();
    WaitForFunction();
});

function WaitForFunction()
{
    if (!$.isFunction(FUNCTION_TO_WAIT_ON_HERE)) {
       setTimeout( WaitForFunction, 100);
       return;
    }
    Function_Loaded();
}

function Function_Loaded(){
      $("#loadingGIF").hide();
}
+9
source

Just name yourself after defining the function. Operators after defining a function will be executed only after reading the previous source text (and, thus, are executed).

+1
source

, , :

  • JavaScript, GIF
  • , GIF .

This should solve your problem in a "simple" way without using timers, etc.

+1
source

All Articles