-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiBanner.html
More file actions
213 lines (209 loc) · 6.55 KB
/
Copy pathmiBanner.html
File metadata and controls
213 lines (209 loc) · 6.55 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width= b , initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
margin:0;
padding:0;
}
ul>li {
list-style: none;
}
.wrapper
{
width:700px;
height: 400px;
margin: 50px auto;
position: relative;
overflow: hidden;
}
.wrapper .pics{
width: 3500px;
height: 100%;
font-size: 0;
position: absolute;
left:0;
top:0;
}
.wrapper .pics li{
display: inline-block;
opacity: 0;
}
.wrapper .pics li.first
{
opacity: 1;
}
.wrapper .pics img{
width: 700px;
height: 400px;
}
.wrapper .buttons
{
width: 100%;
height: 50px;
position: absolute;
top:50%;
}
.wrapper .buttons li{
display: inline-block;
width: 30px;
height: 50px;
background-color: rgba(0,0,0,.5);
color:#fff;
line-height: 52px;
text-align: center;
font-size: 28px;
font-weight: 700;
}
.wrapper .buttons li.left{
float: left;
}
.wrapper .buttons li.right{
float: right;
}
.wrapper .lists
{
width: 100%;
height: 20px;
position: absolute;
left:0;
bottom:20px;
text-align: center;
}
.wrapper .lists li
{
width: 10px;
height: 10px;
display: inline-block;
background-color:#fff;
border-radius: 50%;
margin-right:5px;
}
</style>
</head>
<body>
<div class="wrapper">
<ul class="pics">
<li class="first"><img src="../images/pic1.jpg" alt="" ></li>
<li><img src="../images/pic2.jpg" alt=""></li>
<li><img src="../images/pic3.jpg" alt=""></li>
<li><img src="../images/pic4.jpg" alt=""></li>
<li><img src="../images/pic5.jpg" alt=""></li>
</ul>
<ul class="buttons">
<li class="left"><</li>
<li class="right">></li>
</ul>
<ul class="lists">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<script src="../utils/jquery-3.3.1.js"></script>
<script>
/**在这里我对开发进行总结一下由于在企业开发中我们肯定不是一个人开发我们会是和我们同事一起开发所以 我们开发时一定要注意代码的规范性我总结了一些规范如下
* 1、我们写的代码要使用立即执行函数来包裹起来这样我们的定义的变量即不会影响同事的代码。
* 2、我们在进行网页开发时我们首先要有一个页面初始化函数一般我们定义这个函数为init()负责页面的初 始化。
* 3、我们可以绑定事件写到一个统一的函数数中,这样方便代码的修改。
* 4、我们在进行写函数时一定要保证一个函数功能单一,让一个函数去完成一个功能。
* 5、我们我们写完代码时一定注意我们代码的可维护性。
* 6、最后一点就是我们写代码时一定要注意不要为完成功能而写代码一定要注重代码的优化,该封装函数的 就封装该优化优化。当然这不是一蹴而就的,需要我们后期的不断积累,但是要养成这样的习惯。
* 7、多看看大佬的文章和代码学习人家的思路的写的代码,时刻保持谦虚。
* 8、祝我们可以一起成长。
* @ Fu 2019 2 月27日
*/
;(function(){
var nowIndex=0;
var len =$("img").length;
var timer="";
init();
/**页面初始化函数*/
function init()
{
bindEvent();
slider();
}
/**事件绑定绑定函数*/
function bindEvent()
{
/**左右按钮的点击事件*/
$(".buttons li").on("click",function (){
let flage=$(this).attr("class");
move(flage);
});
/**小圆点绑定事件*/
$(".lists li").on("click",function(){
let index=$(this).index();
move(index);
})
/*鼠标移入时停止伦播*/
$(".wrapper").on("mouseenter",function(){
clearTimeout(timer);
})
/**鼠标移走时开始轮播*/
$(".wrapper").on("mouseleave",function(){
slider();
})
}
/**移动事件*/
function move(param)
{
if(param=="left"||param=="right")
{
if(param=="right")
{
nowIndex++;
nowIndex=nowIndex==len ? '0' : nowIndex;
slider();
}else{
nowIndex--;
nowIndex=nowIndex< 0 ? len-1 : nowIndex;
}
}else
{
nowIndex=param;
}
//移动ul
$(".pics").css({
'left':-nowIndex*700+'px'
});
//每一张图片淡入淡出效果改变opacity
$(".pics li").eq(nowIndex).animate({
'opacity':1
},1000)
//其他图片全部变为0
$(".pics li").css({
'opacity':0
})
/**原点改变函数*/
changeIcon();
}
/**改变图标点的函数*/
function changeIcon()
{
$(".lists li").css({
'background-color':'white',
})
$(".lists li").eq(nowIndex).css({
'background-color':'red'
})
}
//自动轮播函数
function slider()
{
clearTimeout(timer);
timer=setTimeout(function(){
move("right")
},3000)
}
})();
</script>
</body>
</html>