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") ?
$("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");
});
$("*").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.
I think the best is to set up in css file
body.wait *, body.wait {
cursor:wait !important;
}
and add/remove class wait in body
this method overrides all cursors in inputs, links etc.
Example:
$("#loadImage").show();
$("#MyDiv").load("page.php", {limit: 25}, function(){
$("#loadImage").hide();
});
I really think that it's a better solution to just use a class in the body element
$('body').addClass('cursorProgress');
And when you want to keep it as it was before just:
$('body').removeClass('cursorProgress');
and in you css file put something like that:
body.cursorProgress {
cursor: progress;
}
So with this solution you are not overriding the defaults or changes you make on cursor styles, and the second advantage is that you have the possibility of adding the important in your css.
body.cursorProgress {
cursor: progress !important;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With