-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path轮播图2.html
153 lines (149 loc) · 3.88 KB
/
轮播图2.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>轮播图另一种方式实现</title>
<style>
*{
margin: 0;
padding: 0;
}
ul,ol{
list-style: none;
}
a{
text-decoration: none;
}
#container{
width: 680px;
height: 344px;
margin: 50px auto;
position: relative;
overflow: hidden;
}
#tab{
position: absolute;
right: 10px;
bottom: 10px;
}
#tab li{
width: 20px;
height: 20px;
float: left;
background-color: #000000;
color: #ffffff;
line-height: 20px;
text-align: center;
margin-right: 5px;
cursor: pointer;
}
#tab .selected{
background-color: orange;
}
#content{
position: absolute;
}
#content img{
float: left;
}
#arrow{
position: absolute;
left: 10px;
bottom: 10px;
}
#arrow span{
height: 20px;
width: 20px;
background-color: black;
color: white;
float: left;
text-align: center;
line-height: 20px;
margin-right: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="container">
<div id="content">
<img class="selected" src="img/1.jpg" alt="">
<img src="img/2.jpg" alt="">
<img src="img/3.jpg" alt="">
<img src="img/4.jpg" alt="">
</div>
<ul id="tab">
<li class="selected">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<div id="arrow">
<span id="last"><</span>
<span id="next">></span>
</div>
</div>
<script>
window.onload = function () {
var oContainer = document.getElementById("container");
var oUl = document.getElementById("tab");
var aLi = oUl.getElementsByTagName("li");
var oCon = document.getElementById("content");
var aImg = oCon.getElementsByTagName("img");
var oLast = document.getElementById("last");
var oNext = document.getElementById("next");
var iNow = 0;
oCon.style.width = aImg[0].offsetWidth * aImg.length + 'px';
function change(index) {
var i=0;
for(var j=0;j<aImg.length;j++)
{
aLi[j].className = "";
}
aLi[index].className = "selected";
// var timer =setInterval(function () {
// i = i + (aImg[0].offsetWidth/100);
// oCon.style.left = -i + 'px';
// if(i >= index * aImg[0].offsetWidth)
// {
// clearInterval(timer);
// }
// },1);
oCon.style.left = -index * aImg[0].offsetWidth + 'px';
}
for(var i=0;i<aLi.length;i++)
{
aLi[i].index = i;
aLi[i].onmouseover = function () {
change(this.index);
iNow = this.index;
}
}
oNext.onclick = function () {
iNow++;
iNow = iNow%aImg.length;
change(iNow);
};
oLast.onclick = function () {
iNow--;
if(iNow<0)
{
iNow=aImg.length-1;
}
change(iNow);
};
var timer = setInterval(function () {
oNext.onclick();
},3000);
oContainer.onmouseover = function () {
clearInterval(timer);
};
oContainer.onmouseout = function () {
timer = setInterval(function () {
oNext.onclick();
},1000);
}
}
</script>
</body>
</html>