js loading加载效果实现代码

  作者:bea

代码如下: protected void Page_Load(object sender, EventArgs e) { ShowLoading(); System.Threading.Thread.Sleep(10000); ClientScript.RegisterClientScriptBlock(typeof(string), "", "<script>document.body.onload=function(){removeLoadMsg(

代码如下:


protected void Page_Load(object sender, EventArgs e)
{
ShowLoading();
System.Threading.Thread.Sleep(10000);
ClientScript.RegisterClientScriptBlock(typeof(string), "", "<script>document.body.onload=function(){removeLoadMsg();}</script>");
}

/// <summary>
/// 显示页面正在加载中效果
/// </summary>
public void ShowLoading()
{
StringBuilder s = new StringBuilder();
s.Append(" <script language=JavaScript type=text/javascript>
");
s.Append(" var t_id = setInterval(animate,20);
");
s.Append(" var pos=0;var dir=2;var len=0;
");
s.Append(" function animate(){
");
s.Append(" var elem = document.getElementById('progress');
");
s.Append(" if(elem != null) {
");
s.Append(" if (pos==0) len += dir;
");
s.Append(" if (len>32 || pos>79) pos += dir;
");
s.Append(" if (pos>79) len -= dir;
");
s.Append(" if (pos>79 && len==0) pos=0;
");
s.Append(" elem.style.left = pos;
");
s.Append(" elem.style.width = len;
");
s.Append(" }}
");
s.Append(" function removeLoadMsg() {
");
s.Append(" this.clearInterval(t_id);
");
s.Append(" var targelem = document.getElementById('loader_container');
");
s.Append(" targelem.style.display='none';
");
s.Append(" targelem.style.visibility='hidden';
");
s.Append(" }
");
s.Append("</script>
");
s.Append("<style>");
s.Append("#loader_container {text-align:center; position:absolute; top:40%; width:100%; left: 0;}
");
s.Append("#loader {font-family:Tahoma, Helvetica, sans; font-size:11.5px; color:#000000; background-color:#FFFFFF; padding:10px 0 16px 0; margin:0 auto; display:block; width:130px; border:1px solid #5a667b; text-align:left; z-index:9999;}
");
s.Append("#progress {height:5px; font-size:1px; width:1px; position:relative; top:1px; left:0px; background-color:#8894a8;}
");
s.Append("#loader_bg {background-color:#e4e7eb; position:relative; top:8px; left:8px; height:7px; width:113px; font-size:1px;}
");
s.Append("</style>
");
s.Append("<div id=loader_container>
");
s.Append("<div id=loader>
");
s.Append("<div align=center>页面正在加载中...</div>
");
s.Append("<div id=loader_bg><div id=progress> </div></div>
");
s.Append("</div></div>
");
//HttpContext.Current.Response.Write(s.ToString());
HttpContext.Current.Response.Write(s.ToString());
//HttpContext.Current.Response.Flush();




有用  |  无用

猜你喜欢