Steven_Zhigang_Zhang

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
 //优化:将设置提出来Option,作为参数传递
  var Option = {
    msgw : 350,
    msgh : 80,
    titleheight : 25,
    bordercolor : '#336699',
    titlecolor '#99CCFF'
  };

/**
* tips : 提示信息
* options : 设置
* timeout : 超时时间
* callback : 关闭窗口后操作
*/
2 function Alert(tips,option,timeout,callback,) { 3 var msgw,msgh,bordercolor; 4 msgw=350;//提示窗口的宽度 5 msgh=80;//提示窗口的高度 6 titleheight=25 //提示窗口标题高度 7 bordercolor="#336699";//提示窗口的边框颜色 8 titlecolor="#99CCFF";//提示窗口的标题颜色 9 var sWidth,sHeight; 10 //获取当前窗口尺寸 11 sWidth = document.body.offsetWidth; 12 sHeight = document.body.offsetHeight; 13 // //背景div 14 var bgObj=document.createElement("div"); 15 bgObj.setAttribute('id','alertbgDiv'); 16 bgObj.style.position="absolute"; 17 bgObj.style.top="0"; 18 bgObj.style.background="#E8E8E8"; 19 bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75"; 20 bgObj.style.opacity="0.6"; 21 bgObj.style.left="0"; 22 bgObj.style.width = sWidth + "px"; 23 bgObj.style.height = sHeight + "px"; 24 bgObj.style.zIndex = "10000"; 25 document.body.appendChild(bgObj); 26 //创建提示窗口的div 27 var msgObj = document.createElement("div") 28 msgObj.setAttribute("id","alertmsgDiv"); 29 msgObj.setAttribute("align","center"); 30 msgObj.style.background="white"; 31 msgObj.style.border="1px solid " + bordercolor; 32 msgObj.style.position = "absolute"; 33 msgObj.style.left = "50%"; 34 msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif"; 35 //窗口距离左侧和顶端的距离 36 msgObj.style.marginLeft = "-225px"; 37 //窗口被卷去的高+(屏幕可用工作区高/2)-150 38 msgObj.style.top = document.body.scrollTop+(window.screen.availHeight/2)-150 +"px"; 39 msgObj.style.width = msgw + "px"; 40 msgObj.style.height = msgh + "px"; 41 msgObj.style.textAlign = "center"; 42 msgObj.style.lineHeight ="25px"; 43 msgObj.style.zIndex = "10001"; 44 document.body.appendChild(msgObj); 45 //提示信息标题 46 var title=document.createElement("h4"); 47 title.setAttribute("id","alertmsgTitle"); 48 title.setAttribute("align","left"); 49 title.style.margin="0"; 50 title.style.padding="3px"; 51 title.style.background = bordercolor; 52 title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);"; 53 title.style.opacity="0.75"; 54 title.style.border="1px solid " + bordercolor; 55 title.style.height="18px"; 56 title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif"; 57 title.style.color="white"; 58 title.innerHTML="提示信息"; 59 document.getElementById("alertmsgDiv").appendChild(title); 60 //提示信息 61 var txt = document.createElement("p"); 62 txt.setAttribute("id","msgTxt"); 63 txt.style.margin="16px 0"; 64 txt.innerHTML = tips; 65 document.getElementById("alertmsgDiv").appendChild(txt); 66 //设置关闭时间 67 window.setTimeout("closewin("+callback+")",timeout); 68 } 69 function closewin(callback) { 70 document.body.removeChild(document.getElementById("alertbgDiv")); 71 document.getElementById("alertmsgDiv").removeChild(document.getElementById("alertmsgTitle")); 72 document.body.removeChild(document.getElementById("alertmsgDiv"));
    callback();  
73 }

 

posted on 2015-11-02 14:15  Steven_Zhigang_Zhang  阅读(86)  评论(0)    收藏  举报