zsydgithub 1 yıl önce
ebeveyn
işleme
bce7edbf3d

+ 106 - 0
移动端/5_小海豹2.html

@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+  <style>
+    * {
+      margin: 0;
+      padding: 0;
+    }
+
+    h3 {
+      width: 960px;
+      height: 50px;
+      background: #cccccc;
+      text-align: center;
+      line-height: 50px;
+      margin: 0 auto 10px;
+    }
+
+    #imgBox {
+      width: 960px;
+      height: 550px;
+      background: url(img/1.jpg) 0 0 no-repeat;
+      background-size: 100% 100%;
+      margin: 0 auto;
+    }
+
+    #content {
+      width: 960px;
+      margin: 10px auto;
+      overflow: hidden;
+    }
+
+    #left {
+      width: 630px;
+      height: 300px;
+      background: red;
+      float: left;
+    }
+
+    #right {
+      width: 300px;
+      height: 300px;
+      background: blue;
+      float: right;
+    }
+
+    @media screen and (max-width: 960px) {
+      h3 {
+        width: 100%;
+      }
+
+      #imgBox {
+        width: 100%;
+        background-image:  url(img/2.jpg);
+        padding-top: 56%;
+        height: 0;
+        /* background-size: cover; */
+        /* 
+        960  540 
+        100  56%
+        */
+      }
+
+      #content {
+        width: 100%;
+      }
+
+      #left {
+        width: 65%;
+      }
+
+      #right {
+        width: 33%;
+      }
+    }
+    @media screen and (max-width: 480px) {
+      #left{
+        width: 100%;
+      }
+      #right{
+        width: 100%;
+      }
+      #imgBox{
+        background-image: url(img/3.jpg);
+      }
+    }
+  </style>
+</head>
+
+<body>
+  <h3>页眉</h3>
+  <h3>导航</h3>
+  <div id="imgBox"></div>
+  <div id="content">
+    <div id="left"></div>
+    <div id="right"></div>
+  </div>
+  <h3>页脚</h3>
+</body>
+
+</html>

+ 36 - 0
移动端/6_padding-top.html

@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+  <style>
+    *{
+      margin: 0;
+      padding: 0;
+    }
+    #div1{
+      background: red;
+      /* width: 50%;
+      height: 100px; */
+
+      /* width: 50vw;
+      height: 50vh; */
+
+      width: 100%;
+      /* height: 50px; */
+      /* padding-top: 50%; */
+      /* padding-top 百分比  相对于父元素的宽度 */
+      padding-top: 10px;
+      /* 
+      padding-top: 10px; 容器内的内容距离容器顶部有10px  包含在容器内
+      */
+      
+    }
+  </style>
+</head>
+<body>
+  <div id="div1"></div>
+</body>
+</html>

+ 27 - 0
移动端/7_事件.html

@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+<body>
+  123123123131231
+  <script>
+    document.onclick = function(){
+      console.log('click')
+    }
+
+    document.ontouchstart = function(){
+      console.log('touch-start')
+    }
+    document.ontouchmove = function(){
+      console.log('touch-move')
+    }
+    document.ontouchend = function(){
+      console.log('touch-end')
+    }
+  </script>
+</body>
+</html>

+ 125 - 0
移动端/8_点透事件.html

@@ -0,0 +1,125 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+  <style>
+    * {
+      touch-action: none
+    }
+
+    body {
+      margin: 0;
+    }
+
+    .container {
+      width: 100%;
+      overflow: hidden;
+      position: relative;
+    }
+
+    .layer-title {
+      width: 100%;
+      margin: 50px 0;
+      text-align: center;
+    }
+
+    .layer-action {
+      position: absolute;
+      bottom: 20px;
+      width: 100%;
+      text-align: center;
+    }
+
+    .btn {
+      background-color: #08c;
+      border: 0;
+      color: #fff;
+      height: 30px;
+      line-height: 30px;
+      width: 100px;
+    }
+
+    #underLayer {
+      background-color: #eee;
+      width: 90%;
+      height: 500px;
+      line-height: 500px;
+      margin: 30px auto 1000px;
+      text-align: center;
+    }
+
+    #popupLayer {
+      /*display: none;*/
+      background-color: #fff;
+      width: 80%;
+      height: 200px;
+      position: fixed;
+      top: 50%;
+      left: 50%;
+      margin-left: -40%;
+      margin-top: -100px;
+      z-index: 1;
+    }
+
+    #bgMask {
+      position: fixed;
+      top: 0;
+      left: 0;
+      right: 0;
+      bottom: 0;
+      background-color: rgba(0, 0, 0, 0.6);
+    }
+  </style>
+</head>
+
+<body>
+  <div id="container">
+    <div id="underLayer">底层元素</div>
+    <div id="popupLayer">
+      <div class="layer-title">弹出层</div>
+      <div class="layer-action">
+        <button class="btn" id="closePopup">关闭</button>
+      </div>
+    </div>
+  </div>
+  <div id="bgMask"></div>
+  <script type="text/javascript">
+    var oClose = document.querySelector('#closePopup')
+    var oUnder = document.querySelector('#underLayer')
+    oClose.ontouchstart = function (e) {
+      /* 阻止事件默认行为 */
+      e.preventDefault()
+      document.querySelector('#popupLayer').style.display = 'none'
+      document.querySelector('#bgMask').style.display = 'none'
+    }
+
+    // oClose.onclick = function(){
+    //   document.querySelector('#popupLayer').style.display = 'none'
+    //   document.querySelector('#bgMask').style.display = 'none'
+    // }
+    oUnder.onclick = function () {
+      alert('click')
+    }
+    /* 
+    出现点透事件的条件如下:
+    有两层重叠的元素
+    上面的元素带有touch事件  下面的元素是click事件 或者是一个a标签
+      事件流-> touch  -> click
+    上层元素点击需要触发display:none
+
+
+    上层元素点击的时候触发了click事件
+    因为click事件会有延迟时间  而touch会立即触发  所以当点击了上面的事件会触发下面的click、
+
+    解决方案:
+    1、把上层的事件也换成click  不会立即触发  都有延迟
+    2、在上层元素中 通过event.preventDefault()阻止事件默认行为
+    */
+  </script>
+</body>
+
+</html>