8.点透事件.html 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. #container {
  13. width: 100%;
  14. position: relative;
  15. }
  16. #under {
  17. width: 80%;
  18. height: 500px;
  19. margin: 50px auto;
  20. background-color: pink;
  21. }
  22. #dialog {
  23. width: 100%;
  24. height: 100vh;
  25. background-color: rgba(0,0,0,.3);
  26. position: fixed;
  27. top: 0;
  28. left: 0;
  29. right: 0;
  30. bottom: 0;
  31. }
  32. #tips {
  33. width: 300px;
  34. height: 300px;
  35. background-color: #fff;
  36. position: absolute;
  37. top: 100px;
  38. left: 10%;
  39. z-index: 99;
  40. }
  41. #tips #main {
  42. width: 100%;
  43. height: 180px;
  44. text-align: center;
  45. line-height: 180px;
  46. }
  47. #tips #btn {
  48. width: 100px;
  49. height: 50px;
  50. color: #fff;
  51. text-align: center;
  52. line-height: 50px;
  53. margin: 0 auto;
  54. background-color: #00f;
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <div id="container">
  60. <div id="under"></div>
  61. <div id="tips">
  62. <div id="main">弹出层</div>
  63. <div id="close">
  64. <div id="btn">关闭</div>
  65. </div>
  66. </div>
  67. <div id="dialog"></div>
  68. </div>
  69. <script>
  70. var btn = document.getElementById("btn");
  71. var dialog = document.getElementById("dialog");
  72. var under = document.getElementById("under");
  73. btn.onclick = function() {
  74. document.getElementById("tips").style.display = "none";
  75. dialog.style.display = "none";
  76. // alert("弹出")
  77. console.log("222")
  78. }
  79. under.onclick = function() {
  80. // alert("弹出")
  81. console.log("111")
  82. }
  83. // btn.ontouchstart = function() {
  84. // document.getElementById("tips").style.display = "none";
  85. // dialog.style.display = "none";
  86. // // alert("弹出")
  87. // console.log("222")
  88. // }
  89. // under.ontouchstart = function() {
  90. // // alert("弹出")
  91. // console.log("111")
  92. // }
  93. </script>
  94. </body>
  95. </html>