e 1 anno fa
parent
commit
d804904895
2 ha cambiato i file con 159 aggiunte e 0 eliminazioni
  1. 112 0
      day12/html/6.滑入轮播图.html
  2. 47 0
      day12/js/6.滑入轮播图.js

+ 112 - 0
day12/html/6.滑入轮播图.html

@@ -0,0 +1,112 @@
+<!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>
+        * {
+            margin: 0;
+            padding: 0;
+            list-style: none;
+            text-decoration: none;
+            box-sizing: border-box;
+        }
+        #container {
+            width: 590px;
+            height: 470px;
+            margin: 100px auto;
+            overflow: hidden;
+            position: relative;
+        }
+        #imgBox {
+            width: 2950px;
+            height: 470px;
+            /* 过渡效果的css3样式属性
+                符合输出
+                property 规定以什么方式去过渡
+                duration 运动的时间(s/ms)
+                timing-function 运动的方式
+                    linear 匀速
+                delay 运动何时开始 
+            */
+            /* transition: property duration timing-function delay; */
+            position: absolute;
+            left: 0;
+            transition: left 2s linear;
+        }
+        /* 解决行内块元素空白间隙问题
+            1.让所有行内块元素中间无空格
+            2.float 浮动
+        */
+        #imgBox img {
+            float: left;
+        }
+        .list {
+            overflow: hidden;
+            position: absolute;
+            bottom: 10px;
+            right: 10px;
+        }
+        .list li {
+            float: left;
+            width: 20px;
+            height: 20px;
+            background: purple;
+            color: #fff;
+            border-radius: 50%;
+            text-align: center;
+            line-height: 20px;
+            font-size: 14px;
+            margin-left: 10px;
+        }
+        #prev,#next {
+            width: 50px;
+            height: 50px;
+            background: rgb(0, 42, 255);
+            color: #66e21f;
+            font-size: 30px;
+            text-align: center;
+            line-height: 50px;
+            position: absolute;
+            top: 50%;
+            margin-top: -25px;
+        }
+        #prev {
+            left: 0;
+        }
+        #next {
+            right: 0;
+        }
+        .list .selected {
+            background: #f00;
+            color: #ff0;
+        }
+    </style>
+</head>
+<body>
+    <div id="container">
+        <div id="imgBox">
+            <img src="../image/1.jpg" alt="">
+            <img src="../image/2.jpg" alt="">
+            <img src="../image/3.jpg" alt="">
+            <img src="../image/4.jpg" alt="">
+            <img src="../image/5.jpg" alt="">
+        </div>
+        <ul class="list">
+            <li class="selected">1</li>
+            <li>2</li>
+            <li>3</li>
+            <li>4</li>
+            <li>5</li>
+        </ul>
+        <div id="prev">
+            <span>&lt;</span>
+        </div>
+        <div id="next">
+            <span>&gt;</span>
+        </div>
+    </div>
+    <script src="../js/6.滑入轮播图.js"></script>
+</body>
+</html>

+ 47 - 0
day12/js/6.滑入轮播图.js

@@ -0,0 +1,47 @@
+var btn = document.querySelectorAll('.list li');
+console.log(btn);
+var picture = document.getElementsByTagName("img");
+var imgBox = document.getElementById("imgBox");
+var prev = document.getElementById("prev");
+var next = document.getElementById("next");
+var isNow = 0;
+// this=>window
+// 点击小圆点时
+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 = '';
+        }
+        // this=>btn[i]
+        this.className = 'selected';
+        isNow = this.index;
+        imgBox.style.left = -590 * this.index + 'px';
+    }
+}
+
+// 下一张
+next.onclick = function() {
+    isNow++;
+    if(isNow > picture.length - 1) {
+        isNow = 0;
+    }
+    for(var i=0;i<btn.length;i++) {
+        btn[i].className = '';
+    }
+    btn[isNow].className = 'selected';
+    imgBox.style.left = -590 * isNow + 'px';
+}
+
+// 上一张
+prev.onclick = function() {
+    isNow--;
+    if(isNow < 0) {
+        isNow = picture.length -1;
+    }
+    for(var i=0;i<btn.length;i++) {
+        btn[i].className = '';
+    }
+    btn[isNow].className = 'selected';
+    imgBox.style.left = -590 * isNow + 'px';
+}