//loading function showLoad(tipInfo) { var iWidth = 120; //弹出窗口的宽度; var iHeight = 0; //弹出窗口的高度; var scrolltop = 0; var scrollleft = 0; var cheight = 0; var cwidth = 0; var eTip = document.createElement('div'); eTip.setAttribute('id', 'tipDiv'); eTip.style.position = 'absolute'; eTip.style.display = 'none'; eTip.style.border = 'solid 0px #D1D1D1'; eTip.style.backgroundColor = '#4B981D'; eTip.style.padding = '5px 15px'; if(document.body.scrollTop){//这是一个js的兼容 scrollleft=document.body.scrollLeft; scrolltop=document.body.scrollTop; cheight=document.body.clientHeight; cwidth=document.body.clientWidth; } else{ scrollleft=document.documentElement.scrollLeft; scrolltop=document.documentElement.scrollTop; cheight=document.documentElement.clientHeight; cwidth=document.documentElement.clientWidth; } iHeight = eTip.offsetHeight; var v_left=(cwidth-iWidth)/2 + scrollleft; // var v_top=(cheight-iHeight)/2+ scrolltop; eTip.style.left = v_left + 'px'; eTip.style.top = v_top + 'px'; eTip.innerHTML = '<img src=\'Images/loading.gif\' style=\'float:left;\' /> <span style=\'color:#ffffff; font-size:12px\'>' + tipInfo + '</span>'; try { document.body.appendChild(eTip); } catch (e) { } $("#tipDiv").css("float", "right"); $("#tipDiv").css("z-index", "99"); $('#tipDiv').show(); ShowMark(); } function closeLoad() { $('#tipDiv').hide(); HideMark(); } //显示蒙灰层 function ShowMark() { var xp_mark = document.getElementById("xp_mark"); if (xp_mark != null) { //设置DIV xp_mark.style.left = 0 + "px"; xp_mark.style.top = 0 + "px"; xp_mark.style.position = "absolute"; xp_mark.style.backgroundColor = "#000"; xp_mark.style.zIndex = "1"; if (document.all) { xp_mark.style.filter = "alpha(opacity=50)"; var Ie_ver = navigator["appVersion"].substr(22, 1); if (Ie_ver == 6 || Ie_ver == 5) { hideSelectBoxes(); } } else { xp_mark.style.opacity = "0.5"; } xp_mark.style.width = "100%"; xp_mark.style.height = "100%"; xp_mark.style.display = "block"; } else { //页面添加div explainDiv,注意必须是紧跟body 内的第一个元素.否则IE6不正常. $("body").prepend("<div id='xp_mark' style='display:none;'></div>"); ShowMark(); //继续回调自己 } } //隐藏蒙灰层 function HideMark() { var xp_mark = document.getElementById("xp_mark"); xp_mark.style.display = "none"; var Ie_ver = navigator["appVersion"].substr(22, 1); if (Ie_ver == 6 || Ie_ver == 5) { showSelectBoxes(); } }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RunLoading.aspx.cs" Inherits="RunLoading" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Loading效果</title> <script type="text/javascript" src="Scripts/jquery-1.4.4.min.js"></script> <script language="javascript" type="text/javascript"> //show load function Load(title) { $("<div class=\"datagrid-mask\"></div>").css({ display: "block", "100%", height: $(window).height() }).appendTo("body"); $("<div class=\"datagrid-mask-msg\"></div>").html(title).appendTo("body").css({ display: "block", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 }); } //display load function dispalyLoad() { $(".datagrid-mask").remove(); $(".datagrid-mask-msg").remove(); } </script> <style type="text/css"> .datagrid-mask{ position:absolute; left:0; top:0; background:#ccc; opacity:0.3; filter:alpha(opacity=30); display:none; } .datagrid-mask-msg{ position:absolute; cursor1:wait; left:100px; top:50px; auto; font-size:12px; height:16px; padding:12px 5px 10px 30px; background:#fff url('./Images/loading.gif') no-repeat scroll 5px 10px; border:2px solid #6593CF; color:#222; display:none; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="btnLoad" runat="server" Text="显示加载效果" OnClientClick="Load('正在运行,请稍后。。。');" onclick="btnLoad_Click" /> </div> </form> </body> </html>