var ev_msgbox_id=""; //重要 //弹出对话窗口(msgid-要显示的div的id) function ev_modealert(msgid){ //创建大大的背景框 var bgobj=document.createelement("div"); bgobj.setattribute('id','ev_bgmodealertdiv'); document.body.appendchild(bgobj); //背景框满窗口显示 ev_show_bgdiv(); //把要显示的div居中显示 ev_msgbox_id=msgid; ev_show_msgdiv(); } //关闭对话窗口 function ev_closealert(){ var msgobj=document.getelementbyid(ev_msgbox_id); var bgobj=document.getelementbyid("ev_bgmodealertdiv"); msgobj.style.display="none"; document.body.removechild(bgobj); ev_msgbox_id=""; } //窗口大小改变时更正显示大小和位置 window.onresize=function(){ if (ev_msgbox_id.length>0){ ev_show_bgdiv(); ev_show_msgdiv(); } } //窗口滚动条拖动时更正显示大小和位置 window.onscroll=function(){ if (ev_msgbox_id.length>0){ ev_show_bgdiv(); ev_show_msgdiv(); } } //把要显示的div居中显示 function ev_show_msgdiv(){ var msgobj = document.getelementbyid(ev_msgbox_id); msgobj.style.display = "block"; var msgwidth = msgobj.scrollwidth; var msgheight= msgobj.scrollheight; //todo // var bgtop=0; // var bgleft=0; var bgtop=ev_myscrolltop(); var bgleft=ev_myscrollleft(); var bgwidth=ev_myclientwidth(); var bgheight=ev_myclientheight(); var msgtop=bgtop+math.round((bgheight-msgheight)/2); var msgleft=bgleft+math.round((bgwidth-msgwidth)/2); msgobj.style.position = "absolute"; msgobj.style.top = msgtop+"px"; msgobj.style.left = msgleft+"px"; msgobj.style.zindex = "1001"; } //背景框满窗口显示 function ev_show_bgdiv(){ var bgobj=document.getelementbyid("ev_bgmodealertdiv"); var bgwidth=ev_myclientwidth(); var bgheight=ev_myclientheight(); var bgtop=ev_myscrolltop(); var bgleft=ev_myscrollleft(); bgobj.style.position = "absolute"; bgobj.style.top = bgtop+"px"; bgobj.style.left = bgleft+"px"; bgobj.style.width = bgwidth + "px"; bgobj.style.height = bgheight + "px"; bgobj.style.zindex = "1000"; bgobj.style.background = "#444"; bgobj.style.filter = "progid:dximagetransform.microsoft.alpha(style=0,opacity=60,finishopacity=60);"; bgobj.style.opacity = "0.6"; } //网页被卷去的上高度 function ev_myscrolltop(){ var n=window.pageyoffset || document.documentelement.scrolltop || document.body.scrolltop || 0; return n; } //网页被卷去的左宽度 function ev_myscrollleft(){ var n=window.pagexoffset || document.documentelement.scrollleft || document.body.scrollleft || 0; return n; } //网页可见区域宽 function ev_myclientwidth(){ var n=document.documentelement.clientwidth || document.body.clientwidth || 0; return n; } //网页可见区域高 function ev_myclientheight(){ var n=document.documentelement.clientheight || document.body.clientheight || 0; return n; }