js loading加载效果实现代码

(编辑:jimmy 日期: 2024/10/10 浏览:2)

复制代码 代码如下:
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>\n");
s.Append(" var t_id = setInterval(animate,20);\n");
s.Append(" var pos=0;var dir=2;var len=0;\n");
s.Append(" function animate(){\n");
s.Append(" var elem = document.getElementById('progress');\n");
s.Append(" if(elem != null) {\n");
s.Append(" if (pos==0) len += dir;\n");
s.Append(" if (len>32 || pos>79) pos += dir;\n");
s.Append(" if (pos>79) len -= dir;\n");
s.Append(" if (pos>79 && len==0) pos=0;\n");
s.Append(" elem.style.left = pos;\n");
s.Append(" elem.style.width = len;\n");
s.Append(" }}\n");
s.Append(" function removeLoadMsg() {\n");
s.Append(" this.clearInterval(t_id);\n");
s.Append(" var targelem = document.getElementById('loader_container');\n");
s.Append(" targelem.style.display='none';\n");
s.Append(" targelem.style.visibility='hidden';\n");
s.Append(" }\n ");
s.Append("</script>\n");
s.Append("<style>");
s.Append("#loader_container {text-align:center; position:absolute; top:40%; width:100%; left: 0;}\n");
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;}\n");
s.Append("#progress {height:5px; font-size:1px; width:1px; position:relative; top:1px; left:0px; background-color:#8894a8;}\n");
s.Append("#loader_bg {background-color:#e4e7eb; position:relative; top:8px; left:8px; height:7px; width:113px; font-size:1px;}\n");
s.Append("</style>\n");
s.Append("<div id=loader_container>\n");
s.Append("<div id=loader>\n");
s.Append("<div align=center>页面正在加载中...</div>\n");
s.Append("<div id=loader_bg><div id=progress> </div></div>\n");
s.Append("</div></div>\n ");
//HttpContext.Current.Response.Write(s.ToString());
HttpContext.Current.Response.Write(s.ToString());
//HttpContext.Current.Response.Flush();
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。