fengchuanyu 1 semana atrás
pai
commit
68b4a2cd37

+ 62 - 0
7-移动端/7_移动端点击事件.html

@@ -0,0 +1,62 @@
+<!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>
+        .box{
+            width: 200px;
+            height: 200px;
+            background-color: red;
+        }
+        .box2{
+            width: 100px;
+            height: 100px;
+            background-color: blue;
+            position: absolute;
+            top: 50px;
+            left: 50px;
+        }
+    </style>
+</head>
+<body>
+    <div class="box"></div>
+    <div class="box2"></div>
+    <script>
+        var oBox = document.querySelector(".box");
+        var oBox2 = document.querySelector(".box2");
+
+        // 点透事件 需要避免在移动端使用click事件
+        oBox2.ontouchstart = function(){
+            console.log("触摸事件");
+            this.style.display= "none";
+        }
+        oBox.onclick =function(){
+            console.log("点击事件");
+        }
+
+
+
+        // oBox.onclick = function(){
+        //     console.log("hello")
+        // }
+
+        // touchstart 触摸开始
+        // oBox.ontouchstart = function(){
+        //     console.log("触摸开始");
+        // }
+        // // touchend 触摸结束
+        // oBox.ontouchend = function(){
+        //     console.log("触摸结束");
+        // }
+        // // touchmove 触摸移动
+        // oBox.ontouchmove = function(){
+        //     console.log("触摸移动");
+        // }
+
+
+
+    </script>
+</body>
+</html>

+ 26 - 0
7-移动端/js/rem.js

@@ -0,0 +1,26 @@
+;
+(function(win) {
+    var doc = win.document;
+    var docEl = doc.documentElement;
+    var tid;
+
+    function refreshRem() {
+        var width = docEl.getBoundingClientRect().width;
+        var rem = width / 7.5; // 将屏幕宽度分成7.5份, 1份为1rem
+        docEl.style.fontSize = rem + 'px';
+    }
+    
+    win.addEventListener('resize', function() {
+        clearTimeout(tid);
+        tid = setTimeout(refreshRem, 10);
+    }, false);
+    win.addEventListener('pageshow', function(e) {
+        if (e.persisted) {//判断是否加载缓存
+            clearTimeout(tid);
+            tid = setTimeout(refreshRem, 10);
+        }
+    }, false);
+
+    refreshRem();
+
+})(window);

+ 16 - 0
7-移动端/练习4_猫眼电影.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+
+</head>
+<body>
+    <div>hello world</div>
+    <script src="./js/rem.js"></script>
+    <script>
+        
+    </script>
+</body>
+</html>