Developer
Developer

Reputation: 8636

Lock screen with out Thread.sleep or giving some amount of time in jquery

Hi all I am having a requirement where I have to show loading image when I perform any operation. I have gone through several blogs and articles, but all of them are doing some thing like giving some amount of time in Jquery or the scripts used, or using Thread.Sleep method.

Is it possible to do with out these two. Means I don't know how much time it takes to load a page, until and unless the page get loaded I would like to show the waiting screen for the user.

Upvotes: 0

Views: 246

Answers (2)

Rafael Emshoff
Rafael Emshoff

Reputation: 2729

you can use

$(document).load(function() { 

});

from the jQuery library. It waits until all web content has been loaded, and then executes the code within the function. I would build the page, and display a waiting screen wherever in the html where you need it, and then once all content(including images) has been loaded, I can use java script to remove the waiting screens from the html $('.Screen').hide(); That way the user doesn't see the process of each image popping up one at a time, intead sees waiting screens, and then suddenly they're all gone and the images are visible.

Upvotes: 0

John Dvorak
John Dvorak

Reputation: 27287

You can display the loading image when you start some action and remove it when you finish the action:

$("#loading-image").show();
pendingActions ++;
$.get({...,success:function(){
  pendingActions --;
  if(!pendingActions){
    $("#loading-image").hide()
  }
}});

Upvotes: 1

Related Questions