zsydgithub 2 anos atrás
pai
commit
5b7d574849

+ 96 - 0
6_Dom/4_轮播图/3_淡入淡出轮播图.html

@@ -0,0 +1,96 @@
+<!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;
+    }
+    ul{
+      list-style: none;
+    }
+    #container{
+      width: 590px;
+      height: 470px;
+      margin: 100px auto;
+      position: relative;
+    }
+
+    #img-box img{
+      position: absolute;
+      opacity: 0;
+      transition: opacity 1s linear;
+    }
+    #img-box .choice{
+      opacity: 1;
+    }
+    #btns{
+      position: absolute;
+      right: 10px;
+      bottom: 10px;
+    }
+    #btns li{
+      width: 20px;
+      height: 20px;
+      background: aqua;
+      color: white;
+      text-align: center;
+      line-height: 20px;
+      border-radius: 10px;
+      float: left;
+      margin-right: 5px;
+    }
+    #btns .select{
+      background: red;
+    }
+  </style>
+</head>
+
+<body>
+  <div id="container">
+    <div id="img-box">
+      <img class="selected choice" src="image/1.jpg" alt="">
+      <img class="selected" src="image/2.jpg" alt="">
+      <img class="selected" src="image/3.jpg" alt="">
+      <img class="selected" src="image/4.jpg" alt="">
+      <img class="selected" src="image/5.jpg" alt="">
+    </div>
+    <ul id="btns">
+      <li class="select">1</li>
+      <li>2</li>
+      <li>3</li>
+      <li>4</li>
+      <li>5</li>
+    </ul>
+    <div id="next">
+      <span class="iconfont icon-next"></span>
+    </div>
+    <div id="prev">
+      <span class="iconfont icon-prev"></span>
+    </div>
+  </div>
+  <script>
+    var btn = document.getElementsByTagName('li')
+    var img = document.getElementsByClassName('selected')
+
+    for(var i=0;i<btn.length;i++){
+      btn[i].index = i
+      btn[i].onclick = function(){
+        for(var j=0;j<btn.length;j++){
+          btn[j].className = ''
+          img[j].className = 'selected'
+
+        }
+        this.className = 'select'
+        img[this.index].className = 'selected choice'
+      }
+    }
+  </script>
+</body>
+
+</html>

+ 32 - 0
6_Dom/5_获取元素的宽度.html

@@ -0,0 +1,32 @@
+<!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{
+      width: 200px;
+      height: 200px;
+      background: red;
+    }
+  </style>
+</head>
+<body>
+  <div id="div1"></div>
+  <script>
+    var div1 = document.getElementById('div1')
+    div1.style.width = '300px'
+    console.log(div1.offsetWidth)
+    console.log(div1.offsetHeight)
+    console.log(div1.offsetLeft)
+    console.log(div1.offsetTop)
+    console.log(div1.style.width)//内联样式
+  </script>
+</body>
+</html>

+ 54 - 0
6_Dom/6_动画.html

@@ -0,0 +1,54 @@
+<!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{
+      width: 200px;
+      height: 200px;
+      background: red;
+      transition: width 2s linear;
+    }
+  </style>
+</head>
+<body>
+  <button id="up">放大</button>
+  <div id="div1"></div>
+  <button id="down">缩小</button>
+  <script>
+    // var up = document.getElementById('up')
+    // var div1 = document.getElementById('div1')
+    // var down = document.getElementById('down')
+    // up.onclick = function(){
+    //   var timer = setInterval(function(){
+    //     console.log(div1.offsetWidth)
+    //     if(div1.offsetWidth < 500){
+    //       div1.style.width = div1.offsetWidth + 10 +'px'
+    //     } else {
+    //       clearInterval(timer)
+    //     } 
+    //   },10)
+    // }
+    // down.onclick = function(){
+    //   var timer = setInterval(function(){
+    //     console.log(div1.offsetWidth)
+    //     if(div1.offsetWidth > 0){
+    //       div1.style.width = div1.offsetWidth - 10 +'px'
+    //     } else {
+    //       clearInterval(timer)
+    //     }
+    //   },10)
+    // }
+    up.onclick = function(){
+      div1.style.width = '500px'
+    }
+  </script>
+</body>
+</html>