弹出层锁定页面

在页面浮一个层出来,并锁定下面的内容不可选。

JS文件
  1. function NeatDialog(sHTML, sTitle, bCancel) {   
  2.     window.neatDialog = null;   
  3.     this.elt = null;   
  4.     if (document.createElement && document.getElementById) {   
  5.         var dg = document.createElement("div");   
  6.         dg.className = "neat-dialog";   
  7.         if (sTitle) {   
  8.             sHTML = "<div class=/"neat-dialog-title/">" + sTitle + (bCancel ? "<img src=/"x.gif/" alt=/"Cancel/" class=/"nd-cancel/" />" : "") + "</div>/n" + sHTML;   
  9.         }   
  10.         dg.innerHTML = sHTML;   
  11.         var dbg = document.createElement("div");   
  12.         dbg.id = "nd-bdg";   
  13.         dbg.className = "neat-dialog-bg";   
  14.         var dgc = document.createElement("div");   
  15.         dgc.className = "neat-dialog-cont";   
  16.         dgc.appendChild(dbg);   
  17.         dgc.appendChild(dg);   
  18.         if (document.body.offsetLeft > 0) {   
  19.             dgc.style.marginLeft = document.body.offsetLeft + "px";   
  20.         }   
  21.         document.body.appendChild(dgc);   
  22.         if (bCancel) {   
  23.             document.getElementById("nd-cancel").onclick = function () {window.neatDialog.close();};   
  24.         }   
  25.         this.elt = dgc;   
  26.         window.neatDialog = this;   
  27.     }   
  28. }  




调用JS的方法
  1. function openDialog()   
  2. {   
  3.   var sHTML = '<p>Are you sure you want to destroy the world?</p>'+   
  4.   '<p><button οnclick="window.neatDialog.close()">YES!</button></p>';   
  5.   new NeatDialog(sHTML, "NeatDialog!"false);   
  6.  }  


还有CSS
  1. div.neat-dialog-cont {   
  2. background:transparent none repeat scroll 0%;   
  3. height:100%;   
  4. left:0pt;   
  5. position:absolute;   
  6. top:0pt;   
  7. width:100%;   
  8. z-index:98;   
  9. }   
  10. div.neat-dialog-bg {   
  11. background-color:#EEEEEE;   
  12. height:100%;   
  13. left:0pt;   
  14. opacity:0.7;   
  15. position:absolute;   
  16. top:0pt;   
  17. width:100%;   
  18. z-index:-1;   
  19. }   
  20. div.neat-dialog {   
  21. background-color:#FFFFFF;   
  22. border:1px solid #444444;   
  23. margin-left:auto;   
  24. margin-right:auto;   
  25. position:relative;   
  26. top:25%;   
  27. width:30%;   
  28. z-index:99;   
  29. }   
  30. div.neat-dialog-title {   
  31. border-bottom:1px solid #444444;   
  32. font-size:0.8em;   
  33. line-height:1.2em;   
  34. margin:0pt;   
  35. padding:0.1em 0.3em;   
  36. position:relative;   
  37. }  
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值