现在的位置: 首页 > 综合 > 正文

js写的一个好看的Alert

2013年08月02日 ⁄ 综合 ⁄ 共 3738字 ⁄ 字号 评论关闭
Code:
  1. <html>  
  2. <head>  
  3.    <title>  
  4.     </title>  
  5.    <style type="text/css">  
  6.        *{   
  7.            margin:0;padding:0;   
  8.        }   
  9.    .STYLE1 {color: #F9CADE}   
  10.          </style>  
  11. </head>  
  12. <body>  
  13.   
  14. <div class="cecmbody" id="cecmpolicy">  
  15.    <div class="leftClass">  
  16.       <input type="button" value="点击这里" onclick="sAlert('我是一个渐变的sAlert',this);" />  
  17.            </p>  
  18.     <p>测试</p><p>测试</p><p>测试</p><p>测试</p>  
  19.          
  20.     </div>  
  21.    <div class="rightClass">  
  22.    </div>    
  23. </div>  
  24.      <script type="text/javascript" language="javascript">  
  25.     function sAlert(txt){   
  26. var eSrc=(document.all)?window.event.srcElement:arguments[1];   
  27. var shield = document.createElement("DIV");   
  28. shield.id = "shield";   
  29. shield.style.position = "absolute";   
  30. shield.style.left = "0px";   
  31. shield.style.top = "0px";   
  32. shield.style.width = "100%";   
  33. shield.style.height = ((document.documentElement.clientHeight>document.documentElement.scrollHeight)?document.documentElement.clientHeight:document.documentElement.scrollHeight)+"px";   
  34. shield.style.background = "#333";   
  35. shield.style.textAlign = "center";   
  36. shield.style.zIndex = "10000";   
  37. shield.style.filter = "alpha(opacity=0)";   
  38. shield.style.opacity = 0;   
  39. var alertFram = document.createElement("DIV");   
  40. alertFram.id="alertFram";   
  41. alertFram.style.position = "absolute";   
  42. alertFram.style.left = "50%";   
  43. alertFram.style.top = "50%";   
  44. alertFram.style.marginLeft = "-225px" ;   
  45. alertFram.style.marginTop = -75+document.documentElement.scrollTop+"px";   
  46. alertFram.style.width = "450px";   
  47. alertFram.style.height = "150px";   
  48. alertFram.style.background = "#ccc";   
  49. alertFram.style.textAlign = "center";   
  50. alertFram.style.lineHeight = "150px";   
  51. alertFram.style.zIndex = "10001";   
  52. strHtml   = "<ul style=/"list-style:none;margin:0px;padding:0px;width:100%/">/n";   
  53. strHtml += " <li style=/"background:#DD828D;text-align:left;padding-left:20px;font-size:14px;font-weight:bold;height:25px;line-height:25px;border:1px solid #F9CADE;/">[系统提示]</li>/n";   
  54. strHtml += " <li style=/"background:#fff;text-align:center;font-size:12px;height:120px;line-height:120px;border-left:1px solid #F9CADE;border-right:1px solid #F9CADE;/">"+txt+"</li>/n";   
  55. strHtml += " <li style=/"background:#fff;text-align:center;font-size:12px;height:120px;line-height:120px;border-left:1px solid #F9CADE;border-right:1px solid #F9CADE;/"><input type=/"text/" value=/"确 定/"   /></li>/n";   
  56. strHtml += " <li style=/"background:#FDEEF4;text-align:center;font-weight:bold;height:25px;line-height:25px; border:1px solid #F9CADE;/"><input type=/"button/" value=/"确 定/" id=/"do_OK/" onclick=/"doOk()/" /></li>/n";   
  57. strHtml += "</ul>/n";   
  58. alertFram.innerHTML = strHtml;   
  59. document.body.appendChild(alertFram);   
  60. document.body.appendChild(shield);   
  61. this.setOpacity = function(obj,opacity){   
  62.    if(opacity>=1)opacityopacity=opacity/100;   
  63.    try{ obj.style.opacity=opacity; }catch(e){}   
  64.    try{    
  65.     if(obj.filters.length>0&&obj.filters("alpha")){   
  66.      obj.filters("alpha").opacity=opacity*100;   
  67.     }else{   
  68.      obj.style.filter="alpha(opacity=/""+(opacity*100)+"/")";   
  69.     }   
  70.    }catch(e){}   
  71. }   
  72. var c = 0;   
  73. this.doAlpha = function(){   
  74.    if (++c > 20){clearInterval(ad);return 0;}   
  75.    setOpacity(shield,c);   
  76. }   
  77. var ad = setInterval("doAlpha()",1);   
  78. this.doOk = function(){   
  79.    //alertFram.style.display = "none";   
  80.    //shield.style.display = "none";   
  81.    document.body.removeChild(alertFram);   
  82.    document.body.removeChild(shield);   
  83.    eSrc.focus();   
  84.    document.body.onselectstart = function(){return true;}   
  85.    document.body.oncontextmenu = function(){return true;}   
  86. }   
  87. document.getElementById("do_OK").focus();   
  88. eSrc.blur();   
  89. document.body.onselectstart = function(){return false;}   
  90. document.body.oncontextmenu = function(){return false;}   
  91. }   
  92.    </script>  
  93. </body>  
  94. </html>   

 

抱歉!评论已关闭.