I have a page which does some intense and long lasting calculations in Javascript. I would like to have a loading animation to tell the user progress is being made. I have a
You probably don't need it anymore, but just in case anyone else is googling it, here's another simple solution:
*note that it would only work if this huge script execution is being caused by a long iteration loop
-make your loop something like this:
function AsyncLoop(i, lastLoop, parameters) {
setTimeout(function () {
if (i < lastLoop) {
//whatever you wanna do here
window.console.log('iteration ' + i + ': ' + parameters[i].whatevs);
i++;
AsyncLoop(i, lastLoop, parameters);
}
}, 0);
}
-then call it like:
AsyncLoop(0, incredblyLongObjectArray.length, incredblyLongObjectArray);
Here's a little fiddle without using parameters (so it's easier to understand) and with a function to detect if the desirable script has finished executing:
https://jsfiddle.net/or1mrmer/