views:

8228

answers:

5

I want to show to the user a state that the result is loading. How can I change cursor or gif while loading result in div with $MyDiv.load("page.php") ?

+10  A: 
$("body").css("cursor", "progress");

Just remember to return it afterwards:

$MyDiv.load("page.php", function () {
    // this is the callback function, called after the load is finished.
    $("body").css("cursor", "auto");
});
Magnar
+2  A: 
  1. Initially style the loading image non-visible.
  2. Change the style to visible when you begin loading.
  3. Change the style to non-visible when loading finished using a callback argument to load().

Example:

 $("#loadImage").show();
 $("#MyDiv").load("page.php", {limit: 25}, function(){
   $("#loadImage").hide();
 });
Craig Stuntz
To actually create the loading gif, check out http://www.ajaxload.info/ where you can customize one and save it.
Darwyn
A: 

Anyone using the $("body").css("cursor", "progress") technique experiencing that you have to move the cursor after the callback to make it change back to default/auto ? IE and Chrome seem to have this problem, but FF handles it great.

Bobmoff
@Magnar - I does not seem to matter if I set it back using javascript directly on the body element or switching a class on it, it still only reacts when I move the mouse. Could you show me an example of this working in IE and Chrome I would be very happy!
Bobmoff
+3  A: 

$("*").css("cursor", "progress") will work no matter where on the page you are currently pointing. This way you do not have to move the cursor to see it activated.

mountain
A: 

I think the best is to set up in css file

body.wait * {
cursor:wait !important;
}

and add/remove class wait in body

this method overrides all cursors in inputs, links etc.

Marmot