I have a function showLoading()
that shows a spinner by appending a class:
function showLoading(){
//console.log("show loading");
loading = true;
$("body").addClass("loading");
}
I call it like this:
Function heavyCrunch(){
showLoading();
<heavy crunching>
hideLoading();
}
Now whenever I call the function just before some heavy load which takes > 1 second, it should show the spinner immediately, but it does not. In fact, it doesn't show at all. Whenever I click a button that triggers the heavyCrunch()
function, it just freezes for a second or 2 and then immediately show the result. The spinner never shows. Why does this happen?
Should I call the function in an .after
callback or something?