- 实现自动左右轮播
- 鼠标移入停止轮播,鼠标移开继续轮播
- prev next点击左右切换
- 点击下边导航可以跳转到相应的页
首先引入自己封装的简单的js运动库 move.js1
<script src="move.js"></script>
1 | function getStyle(obj, name) { |
javascript代码如下:
1 | function getByClass(oParent, sClass) { |
html代码如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21<div class="container" id="container">
<div id="bd">
<ul>
<li><img src="images/0.jpg" alt=""></li>
<li><img src="images/1.jpg" alt=""></li>
<li><img src="images/2.jpg" alt=""></li>
<li><img src="images/3.jpg" alt=""></li>
</ul>
</div>
<div class="control" id="control">
<span class="prev" id="prev">‹</span>
<span class="next" id="next">›</span>
</div>
<p class="navigtion"><span class="nowNav">1</span>/<span class="navig"></span></p>
<div id="hd">
<span class="cur"></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
css代码如下: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
93body {
margin: 0;
padding: 0;
}
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
.container {
position: relative;
width: 1200px;
height: 610px;
margin: 150px auto;
overflow: hidden;
}
.container #bd ul,
.container #bd li {
height: 100%;
}
.container #bd ul {
position: absolute;
top: 0;
left: 0;
}
.container #bd li {
float: left;
width: 1200px;
}
.container #bd li img {
height: 100%;
width: 100%;
}
.control span {
position: absolute;
top: 0;
bottom: 0;
z-index: 19;
width: 32px;
height: 32px;
margin: auto;
background: #ff0;
font-size: 32px;
line-height: 30px;
text-align: center;
cursor: pointer;
}
.control span.next {
right: 0;
}
#hd {
position: absolute;
z-index: 29;
width: 20%;
left: 0;
right: 0;
margin: auto;
bottom: 2%;
text-align: center;
}
#hd span {
width: 10px;
height: 10px;
background: #f00;
border-radius: 50%;
display: inline-block;
cursor: pointer;
}
#hd .cur {
background: #ff0;
}
.navigtion {
position: absolute;
bottom: 3%;
width: 10%;
/* margin: 0 auto; */
display: block;
text-align: center;
left: 45%;
}