fengchuanyu 2 semanas atrás
pai
commit
6c91db80ae

+ 40 - 0
4-BOM&DOM/15_鼠标按下抬起.html

@@ -0,0 +1,40 @@
+<!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;
+            margin: 100px auto;
+        }
+    </style>
+</head>
+<body>
+    <div id="box"></div>
+    <script>
+        var oBox = document.getElementById("box");
+
+        oBox.onmousedown = function(e){
+            console.log("鼠标按下");
+            // offsetX , offsetY 获取鼠标点击位置 距离 元素左上角的位置
+            console.log(e.offsetX, e.offsetY);
+        }
+
+        oBox.onmouseup = function(){
+            console.log("鼠标抬起");
+
+            // 当鼠标抬起的时候移除鼠标移动事件
+            oBox.onmousemove = null;
+        }
+
+        oBox.onmousemove = function(){
+            console.log("鼠标移动");
+        }
+
+    </script>
+</body>
+</html>

+ 76 - 0
4-BOM&DOM/练习7_DOM进度条.html

@@ -0,0 +1,76 @@
+<!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>
+        .progress{
+            width: 500px;
+            height: 50px;
+            border:3px solid black;
+            border-radius: 10px;
+            line-height: 50px;
+            padding-left: 50px;
+            box-sizing: border-box;
+            position: relative;
+            overflow: hidden;
+        }
+        .progress-bg{
+            width: 0;
+            height: 100%;
+            background-color: blue;
+            position: absolute;
+            top: 0;
+            left: 0;
+        }
+        .progress-num{
+            position: relative;
+            z-index: 1;
+        }
+    </style>
+</head>
+<body>
+    <div class="progress">
+        <span class="progress-num">0%</span>
+        <div class="progress-bg"></div>
+    </div>
+    <button>开始</button>
+    <script>
+        // 第一步获取元素
+        // 获取按钮
+        var progressBtn = document.getElementsByTagName("button");
+        progressBtn = progressBtn[0];
+        // 获取进度条
+        var progressBg = document.getElementsByClassName("progress-bg");
+        progressBg = progressBg[0];
+        // 获取进度条文字
+        var progressNum = document.getElementsByClassName("progress-num");
+        progressNum = progressNum[0];
+        //用来存储定时器
+        var timer = null;
+        // 定义变量存储进度数字
+        var num = 0;
+
+        // 第二步为按钮绑定事件
+        progressBtn.onclick = function(){
+            // 通过offsetWidth 获取元素宽度
+            var thisWidth = progressBg.offsetWidth;
+            // 设置一个定时函数实现动画过度效果
+            timer = setInterval(function(){
+                thisWidth += 5;
+                num++
+                if(thisWidth <= 500){
+                    progressBg.style.width = thisWidth + "px";
+                    progressNum.innerText = num + "%";
+                }else{
+                    clearInterval(timer);
+                }
+                
+
+                // progressBg.style.width = (thisWidth + 10) + "px";
+            },16);
+        }
+    </script>
+</body>
+</html>