图片轮播效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>ECharts</title>
    <style>
        /* 主体部分 */
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        img{
            width: 680px;
            height: 340px;
        }
        #slider{
           position: relative;
            width: 680px;
            height: 340px;
            margin: 100px auto;
            /* outline: 2px solid red; */
            overflow: hidden;
        }
        .slider-list{
            display: flex;
            position: relative;
            left: 0px;
            width: 100%;
            height: 100%;
            /* transform: translateX(-680px); */
            transition: all 1s;
        }
        .slider-list li{
            width: 680px;
            height: 340px;
        }
        /* 小点部分 */
        .dot-list{
           position: absolute;
           bottom: 10px;
          left: 50%;
          transform: translateX(-50%);
          padding: 2px 10px;
          border-radius: 12px;
          background-color: rgba(255, 255, 255, .3);
        }
        .dot-list .dot{
            display: inline-block;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: white;
        }
        .dot-list .dot.cur{
            background-color: red;
        }
        /*箭头部分  */
        .arraw{
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            width: 30px;
            height: 60px;
            background-color: rgba(0, 0, 0, 0.795);
            display: none;
        }
        .prev{
            left: 0;
        }
        .next{
            right: 0;
        }
        .arraw span{
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(50%,50%);
            width: 10px;
            height: 10px;
            border-bottom:2px solid white;
            border-left:2px solid white;
        }
        .prev span{
            transform: translate(-50%,-50%) rotate(45deg);
        }
        .next span{
            transform: translate(-50%,-50%) rotate(-135deg);
        }
        #slider:hover .arraw{
            display: block;
        }
    </style>
  </head>
  <body>
    <div id="slider">
        <!-- 图片部分 -->
        <ul class="slider-list">
            <!-- <li><a href="#"><img src="./img/5.jpg"></a></li> -->
            <li><a href="#"><img src="./img/demo1.jpg"></a></li>
            <li><a href="#"><img src="./img/demo2.jpg"></a></li>
            <li><a href="#"><img src="./img/demo3.jpg"></a></li>
            <li><a href="#"><img src="./img/demo4.jpg"></a></li>
            <li><a href="#"><img src="./img/demo5.jpg"></a></li>
            <li><a href="#"><img src="./img/demo1.jpg"></a></li>
        </ul>
         <!-- 小点部分 -->
       <div class="dot-list">
        <span class="dot cur"></span>
        <span class="dot"></span>
        <span class="dot"></span>
        <span class="dot"></span>
        <span class="dot"></span>
    </div>
    <!--箭头布分 -->
    <a href="#" class="arraw prev" id="left">
        <span></span>
    </a>
    <a href="#" class="arraw next" id="right">
     <span></span>
    </a>
         
    </div>
    <script>
         var slid =document.getElementById('slider');
            var slidLis=slid.getElementsByTagName('ul')[0];
            // var slidLis=document.querySelector(".slider-list")
            var slidLi=slidLis.getElementsByTagName('li');
          
            var lef = document.getElementById('left');
            var righ = document.getElementById('right');
             
            var index = 0;
            function lun(){
               index++;
                circe();
               slidLis.style.left=index*-680 + "px";
               slidLis.style.transition="all 1s";
               if(index === 5){
                   index= 0;
                   setTimeout(function(){
                       slidLis.style.left=0;
                       slidLis.style.transition="none";
                   },1000)
               }
               circe();
            }
            righ.addEventListener("click",lun);
            lef.addEventListener("click",function(){
                index--;
                if(index === -1){
                    slidLis.style.left=5*-680 + "px";
                    slidLis.style.transition="none";
                     index = 4;
                    setTimeout(function(){
                        slidLis.style.left=index*-680 + "px";
                    slidLis.style.transition="all 1s";
                    },0); 
                }else{
                    slidLis.style.left=index*-680 + "px";
                }
                circe();
            });
        //  自动轮播
        var autoplay = setInterval(lun,2000);
        slid.addEventListener("mouseenter",function(){
            clearInterval(autoplay);
        });
        slid.addEventListener("mouseleave",function(){
            clearInterval;
            autoplay = setInterval(lun,2000);
        })
          
        //小圆点
          
        var dotList = document.getElementsByTagName('span');
        function circe(){
            for(var i = 0;i < dotList.length;i++){
                  if(i === index){
                      dotList[i].classList.add("cur");
                  }else{
                    dotList[i].classList.remove("cur");
                  }
            }
        }
    </script>
  </body>
</html>

  

posted @   李昂唐  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示