I'm trying to adapt this solution to my needs: How can I create a "Please Wait, Loading..." animation using jQuery?
Basically a really awesome scheme is provided to wrap Ajax requests with a nice loading GUI. I'm trying to do the same for a function I have that does some calculations and then appends some graphics to the DOM.
So what I've tried is this:
$("body").addClass("loading");
long_time_taking_function(mainDiv);
$("body").removeClass("loading");
Unfortunately it appears as though the class is added and then removed instantly, either before or after the long_time_taking_function() executes. However I know that adding the class works, because commenting out the removeClass() call keeps the gif floating on the page.
Any ideas how I can make this work? I can provide more details about the intermediate function if needed.
Cheers