How would i get my cursor to change to this loading icon when a function is ca
If it saves too fast, try this:
<style media="screen" type="text/css">
.autosave {display: inline; padding: 0 10px; color:green; font-weight: 400; font-style: italic;}
</style>
<input type="button" value="Save" onclick="save();" />
<span class="autosave" style="display: none;">Saved Successfully</span>
$('span.autosave').fadeIn("80");
$('span.autosave').delay("400");
$('span.autosave').fadeOut("80");
The following is my preferred way, and will change the cursor everytime a page is about to change i.e. beforeunload
$(window).on('beforeunload', function(){
$('*').css("cursor", "progress");
});
$('#some_id').click(function() {
$("body").css("cursor", "progress");
$.ajax({
url: "test.html",
context: document.body,
success: function() {
$("body").css("cursor", "default");
}
});
});
This will create a loading cursor till your ajax call succeeds.
In your jQuery use:
$("body").css("cursor", "progress");
and then back to normal again
$("body").css("cursor", "default");
jQuery:
$("body").css("cursor", "progress");
back again
$("body").css("cursor", "default");
Pure:
document.body.style.cursor = 'progress';
back again
document.body.style.cursor = 'default';
Please don't use jQuery for this in 2018! There is no reason to include an entire external library just to perform this one action which can be achieved with one line:
Change cursor to spinner: document.body.style.cursor = 'wait';
Revert cursor to normal: document.body.style.cursor = 'default';