模拟一个弹出层
今天网上找了一些资料,模仿做了一个alert();
alert弹出的东西不支持复制,在实际项目中,有时弹出信息用户需要立马将他们全部记下来,稍微的快捷方式就是将弹出信息复制下来,所以为了方便用户吧,模拟了一个弹窗,样子丑了点!
1 function sAlert(str){ 2 var msgw,msgh,bordercolor; 3 msgw=400;//提示窗口的宽度 4 msgh=200;//提示窗口的高度 5 titleheight=25 //提示窗口标题高度 6 bordercolor="#DDDDDD";//提示窗口的边框颜色 7 // titlecolor="#99CCFF";//提示窗口的标题颜色 8 var sWidth,sHeight; 9 sWidth=document.body.offsetWidth; 10 sHeight=screen.height; 11 var bgObj=document.createElement("div"); 12 bgObj.setAttribute('id','bgDiv'); 13 bgObj.style.position="absolute"; 14 bgObj.style.top="0"; 15 bgObj.style.background="#777"; 16 bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75"; 17 bgObj.style.opacity="0.6"; 18 bgObj.style.left="0"; 19 bgObj.style.width=sWidth + "px"; 20 bgObj.style.height=sHeight + "px"; 21 bgObj.style.zIndex = "10000"; 22 document.body.appendChild(bgObj); 23 var msgObj=document.createElement("div") 24 msgObj.setAttribute("id","msgDiv"); 25 msgObj.setAttribute("align","center"); 26 msgObj.style.background="white"; 27 msgObj.style.border="1px solid " + bordercolor; 28 msgObj.style.position = "absolute"; 29 msgObj.style.left = "50%"; 30 msgObj.style.top = "50%"; 31 msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif"; 32 msgObj.style.marginLeft = "-225px" ; 33 msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px"; 34 msgObj.style.width = msgw + "px"; 35 msgObj.style.height =msgh + "px"; 36 msgObj.style.textAlign = "center"; 37 msgObj.style.lineHeight ="25px"; 38 msgObj.style.zIndex = "10001"; 39 // msgObj.style.word-wrap = "break-word"; 40 msgObj.style.overflowY="scroll"; 41 var title=document.createElement("h2"); 42 title.setAttribute("id","msgTitle"); 43 title.setAttribute("align","right"); 44 title.style.margin="0"; 45 title.style.padding="3px"; 46 title.style.background=bordercolor; 47 title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);"; 48 title.style.opacity="0.75"; 49 title.style.border="1px solid " + bordercolor; 50 title.style.height="18px"; 51 title.style.font="13px Verdana, Geneva, Arial, Helvetica, sans-serif"; 52 title.style.color="#000000"; 53 title.style.cursor="pointer"; 54 title.innerHTML="关闭"; 55 title.onclick=function(){ 56 document.body.removeChild(bgObj); 57 document.getElementById("msgDiv").removeChild(title); 58 document.body.removeChild(msgObj); 59 } 60 document.body.appendChild(msgObj); 61 document.getElementById("msgDiv").appendChild(title); 62 var txt=document.createElement("p"); 63 // txt.style.margin="1em 0" 64 txt.setAttribute("id","msgTxt"); 65 txt.style.fontSize = "13px"; 66 txt.innerHTML = "注意:导入成功,不存在一下联系人手机号码:"+str; 67 // txt.style.overflowY="scroll"; 68 document.getElementById("msgDiv").appendChild(txt); 69 }
最终测试弹出样子为以下,不忍直视:::::::::::::
粗来吧!
tips
时间,请带我像一条小溪流般,安静地流淌,汇入爱的海洋。