|
@@ -0,0 +1,102 @@
|
|
|
|
+<!DOCTYPE html>
|
|
|
|
+<html lang="en">
|
|
|
|
+ <head>
|
|
|
|
+ <meta charset="UTF-8" />
|
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
|
|
+ <title>Document</title>
|
|
|
|
+ <style>
|
|
|
|
+ * {
|
|
|
|
+ margin: 0;
|
|
|
|
+ padding: 0;
|
|
|
|
+ /* 触摸行为 */
|
|
|
|
+ touch-action: none;
|
|
|
|
+ }
|
|
|
|
+ #container {
|
|
|
|
+ width: 100%;
|
|
|
|
+ position: relative;
|
|
|
|
+ }
|
|
|
|
+ #under {
|
|
|
|
+ width: 90%;
|
|
|
|
+ height: 500px;
|
|
|
|
+ font-size: 24px;
|
|
|
|
+ text-align: center;
|
|
|
|
+ line-height: 500px;
|
|
|
|
+ background: #eee;
|
|
|
|
+ margin: 25px auto;
|
|
|
|
+ }
|
|
|
|
+ #dialog {
|
|
|
|
+ width: 80%;
|
|
|
|
+ height: 300px;
|
|
|
|
+ background: #fff;
|
|
|
|
+ position: absolute;
|
|
|
|
+ top: 120px;
|
|
|
|
+ left: 38px;
|
|
|
|
+ z-index: 99;
|
|
|
|
+ }
|
|
|
|
+ #title {
|
|
|
|
+ width: 100%;
|
|
|
|
+ height: 200px;
|
|
|
|
+ text-align: center;
|
|
|
|
+ line-height: 200px;
|
|
|
|
+ }
|
|
|
|
+ #action {
|
|
|
|
+ position: absolute;
|
|
|
|
+ top: 200px;
|
|
|
|
+ left: 100px;
|
|
|
|
+ }
|
|
|
|
+ #close {
|
|
|
|
+ width: 100px;
|
|
|
|
+ height: 35px;
|
|
|
|
+ text-align: center;
|
|
|
|
+ line-height: 35px;
|
|
|
|
+ color: #fff;
|
|
|
|
+ background: #00f;
|
|
|
|
+ }
|
|
|
|
+ #mask {
|
|
|
|
+ width: 100%;
|
|
|
|
+ background: rgba(0, 0, 0, .5);
|
|
|
|
+ position: fixed;
|
|
|
|
+ top: 0;
|
|
|
|
+ left: 0;
|
|
|
|
+ right: 0;
|
|
|
|
+ bottom: 0;
|
|
|
|
+ }
|
|
|
|
+ </style>
|
|
|
|
+ </head>
|
|
|
|
+ <body>
|
|
|
|
+ <div id="container">
|
|
|
|
+ <div id="under">底层元素</div>
|
|
|
|
+ <div id="dialog">
|
|
|
|
+ <div id="title">弹出层</div>
|
|
|
|
+ <div id="action">
|
|
|
|
+ <div id="close">关闭</div>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ <div id="mask"></div>
|
|
|
|
+ </div>
|
|
|
|
+ <script>
|
|
|
|
+ var close = document.getElementById("close");
|
|
|
|
+ var under = document.getElementById("under");
|
|
|
|
+ /**
|
|
|
|
+ * 点透事件
|
|
|
|
+ * 1.两层元素叠加到一起
|
|
|
|
+ * 2.第一层是touch事件
|
|
|
|
+ * 3.第二层是click事件或者a标签
|
|
|
|
+ *
|
|
|
|
+ *
|
|
|
|
+ * 解决方案:
|
|
|
|
+ * 1.event.preventDefault()
|
|
|
|
+ * 2.将click事件全部换成touch
|
|
|
|
+ * */
|
|
|
|
+ close.ontouchstart = function(event) {
|
|
|
|
+ // event.preventDefault();
|
|
|
|
+ document.getElementById("dialog").style.display = 'none';
|
|
|
|
+ document.getElementById("mask").style.display = 'none';
|
|
|
|
+ }
|
|
|
|
+ // touchstart => touchmove => touchend
|
|
|
|
+ under.onclick = function() {
|
|
|
|
+ alert("弹出");
|
|
|
|
+ }
|
|
|
|
+ </script>
|
|
|
|
+ </body>
|
|
|
|
+</html>
|