Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style>
  7. html,body{
  8. padding:0;
  9. margin: 0;
  10. font-size: 14px;
  11. width: 100%;
  12. height: 100%;
  13. overflow: hidden;/*不出现滚动条*/
  14. }
  15. input{
  16. display: block;
  17. width: 100px;
  18. height: 30px;
  19. line-height: 30px;
  20. margin:20px auto;
  21. }
  22. #bg{
  23. width: 100%;
  24. height:100%;
  25. position:absolute;
  26. left:0;
  27. top:0;
  28. z-index: 1;
  29. background-color:rgba(0,0,0,0.5);
  30. }
  31. #layer{
  32. width: 300px;
  33. height: 300px;
  34. border:1px solid #ccc;
  35. background-color: #fff;
  36. position: absolute;
  37. z-index:2;
  38. border-radius:50px 150px;
  39. background: repeating-radial-gradient(#ff0,green);
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <input type="button" value="login" id="btn"/>
  45. <script>
  46.  
  47. var btn=document.getElementById("btn");
  48. //获取当前屏幕的宽和高
  49. var cw=document.body.clientWidth||document.documentElement.clientWidth;
  50. var ch=document.body.clientHeight||document.documentElement.clientHeight;
  51. //绑定点击事件
  52. btn.onclick=function(){
  53. //动态的创建弹出层
  54. var bg=document.createElement("div");
  55. bg.id="bg";
  56. var layer=document.createElement("div");
  57. layer.id="layer";
  58. //动态的添加元素到页面中
  59. document.body.appendChild(bg);
  60. document.body.appendChild(layer);
  61. var x=(cw-layer.offsetWidth)/2;
  62. var y=(ch-layer.offsetHeight)/2;
  63. layer.style.left=x+"px";
  64. layer.style.top=y+"px";
  65. bg.onclick=function(){
  66. document.body.removeChild(this);
  67. document.body.removeChild(layer);
  68. }
  69. };
  70. </script>
  71. </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement