e 11 달 전
부모
커밋
893abf1f58
3개의 변경된 파일139개의 추가작업 그리고 0개의 파일을 삭제
  1. 28 0
      js/js初阶/DOM/7.获取元素宽度.html
  2. 45 0
      js/js初阶/DOM/8.动画.html
  3. 66 0
      js/js初阶/DOM/9.事件.html

+ 28 - 0
js/js初阶/DOM/7.获取元素宽度.html

@@ -0,0 +1,28 @@
+<!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: 300px;
+            height: 200px;
+            border:2px solid #000;
+        }
+    </style>
+</head>
+<body>
+    <div id="box"></div>
+    <script>
+        var box = document.getElementById("box");
+        console.log(box.offsetWidth);//xxx.offsetWidth 元素宽度
+        console.log(box.offsetHeight);//xxx.offsetHeight 元素高度
+        box.onclick = function(event) {
+            console.log(event.clientX,event.clientY);
+            // clientX 当前元素点击时x轴位置坐标
+            // clientY 当前元素点击时y轴位置坐标
+        }
+    </script>
+</body>
+</html>

+ 45 - 0
js/js初阶/DOM/8.动画.html

@@ -0,0 +1,45 @@
+<!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: #00f;
+            /* 平滑的过渡效果
+                transition:
+                    执行效果的元素属性 执行完的时间 执行时的运动状态 延迟时间
+                    linear	规定以相同速度开始至结束的过渡效果(等于 cubic-bezier(0,0,1,1))。
+                    ease	规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))。
+                    ease-in	规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1))。
+                    ease-out	规定以慢速结束的过渡效果(等于 cubic-bezier(0,0,0.58,1))。
+                    ease-in-out	规定以慢速开始和结束的过渡效果(等于 cubic-bezier(0.42,0,0.58,1))。
+                    cubic-bezier(n,n,n,n)	在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数
+            */
+            transition: width 2s linear 0;
+        }
+    </style>
+</head>
+<body>
+    <div id="box"></div>
+    <button id="btn1">放大</button>
+    <button id="btn2">缩小</button>
+    <script>
+        var box = document.getElementById("box");
+        var btn1 = document.getElementById("btn1");
+        var btn2 = document.getElementById("btn2");
+        btn1.onclick = function() {
+            console.log("走进来")
+               var timer = setInterval(function(){
+                box.style.width = box.offsetWidth + 10 + 'px';
+                if(box.offsetWidth >= 500) {
+                    clearInterval(timer);
+                }
+            },20)
+        }
+    </script>
+</body>
+</html>

+ 66 - 0
js/js初阶/DOM/9.事件.html

@@ -0,0 +1,66 @@
+<!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: 300px;
+            height: 300px;
+            background: #ff0;
+        }
+    </style>
+</head>
+<body>
+    <div id="box"></div>
+    <input type="text">
+    <script>
+        var box = document.getElementById("box");
+        var inp = document.querySelector("input");
+        // 1.点击事件
+        // box.onclick = function() {
+        //     console.log("点击");
+        // }
+        // 2.双击
+        // box.ondblclick = function() {
+        //     console.log("双击")
+        // }
+        // 3.鼠标滑动
+        // box.onmousemove = function(){
+        //     console.log("鼠标滑动")
+        // }
+        // 4.鼠标划出
+        // box.onmouseout = function(){
+        //     console.log("鼠标划出")
+        // }
+        // 5.鼠标划入
+        // box.onmouseover = function() {
+        //     console.log("鼠标划入")
+        // }
+        // 6.鼠标按下
+        box.onmousedown = function() {
+            console.log("鼠标按下")
+        }
+        // 7.鼠标抬起
+        box.onmouseup = function(){
+            console.log("鼠标抬起")
+        }
+        // 8.键盘按下
+        inp.onkeydown = function(eve) {
+            console.log("键盘按下",eve)
+            if(eve.keyCode == 9) {
+                console.log("按下tab")
+            }
+        }
+        // 9.键盘抬起
+        // inp.onkeyup = function() {
+        //     console.log("键盘抬起")
+        // }
+        // 10.键盘按下 回车键
+        // inp.onkeypress = function() {
+        //     console.log("键盘按下")
+        // }
+    </script>
+</body>
+</html>