I have a chunk of javascript that changes the opacity of the web page, positions an animated GIF in the middle of the screen, then fires an XMLHttpRequest to the server to collect data. When the XMLHttpRequest object gets to the Send method, the animation stops until the object gets a response from the server. It's mostly cosmetic but annoying because it looks like the browser is frozen for that 1-2 second period.
Code:
// CHANGE OPACITY AND TURN ON ANIMATED GIF
var v2 = document.getElementById("mainDiv");
v2.style.opacity = "0.3";
var v2 = document.getElementById("loaderDiv");
v2.style.display = "block";
// SMALL DELAY TO ALLOW ABOVE CODE TO TAKE AFFECT
// WINDOW DIMS AND ANIMATED GIF STARTS SPINNING
window.setTimeout(function() {
// GOTO THE SERVER AND GET DATA
var objHttp = new XMLHttpRequest();
var objDate = new Date();
var urlRef = "mobile_expanded.asp?siteId=" + siteId + "&uUrl=" + objDate.getTime();
objHttp.open("GET",urlRef,false);
objHttp.send("");
var strResponse = objHttp.responseText;
//PLACE DATA IN WEB PAGE
v1.innerHTML = strResponse;
v1.style.display = "block";
//UNDO OPACITY AND TURN OFF ANIMATED GIF.
var v2 = document.getElementById("mainDiv");
v2.style.opacity = "1.0";
var v2 = document.getElementById("loaderDiv");
v2.style.display = "none";
},1000);