Javascript simulation implements an ajax load box instance

  • 2020-03-30 04:07:21
  • OfStack

This article illustrates the javascript simulation of ajax loading box method, to share with you for your reference. Specific methods are as follows:

function loading(p_value,str)
{
if (p_value)
{
if (!document.getElementById("load_area"))
{
var para1 = document.createElement("span");
var node=document.createTextNode(str);
para1.appendChild(node);
var para=document.createElement("div");
para.id="load_area"; 
var top=document.body.scrollTop+document.documentElement.scrollTop;//Gets the actual height in the page
top_position = top+157 + "px";
para.style.top =top_position;
icon.style.cssText += ";vertical-align:middle;padding-right:4px;margin-top:-2px;"
para.style.cssText +=
";position:absolute;left:50%;width:140px;margin-left:-70px;height:50px;line-height:50px;font-size:18px;text-overflow:ellipsis;overflow:hidden; white-space:nowrap;text-align:center;background-color: #000;border-radius:2px;-webkit-box-shadow:0 2px 2px rgba(0,0,0,0.5);color:#eee;"; var icon = new Image();
icon.src="images/loading1.gif";//I'm going to replace
with the actual path document.body.appendChild(para); para.appendChild(icon); para.appendChild(para1); }
else
{
document.getElementById("load_area").style.display="block";
}
}
else
{
document.getElementById("load_area").style.display="none";
}
}

The method is as follows:

loading(true," In the load ...");  loading(false)


Related articles: