I would like to do something as simple as this:
Basically, I toggle the visibility of a loader element, then I simulate the processing of something by waiting 10 seconds and finally I toggle the visibility again. My problem is that I would like to force the redraw inside the testLoader callback function, but so far the update of the elements is only done after the callback has finished its execution. Is there a way of redrawing while the button callback is being executed?
testLoader : function() {
var loader = document.getElementById("loader")
var loaderVisibility = loader.style.visibility;
if (loaderVisibility == "visible") {
loader.style.visibility = "hidden"
} else {
loader.style.visibility = "visible"
}
var ms = 10000;
var start = new Date().getTime();
var end = start;
while (end < start + ms) {
end = new Date().getTime();
}
if (loaderVisibility == "visible") {
loader.style.visibility = "hidden"
} else {
loader.style.visibility = "visible"
}
}
<input type="button" id="testLoaderButton" value="Test Loader" onClick="testLoader()" />