-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path轮播图.html
178 lines (176 loc) · 3.55 KB
/
轮播图.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin:0;
padding:0;
}
ul{
list-style:none;
}
#imgs .select{
display:block;
}
#imgs img{
display:none;
}
#container{
position:relative;
width:730px;
height:454px;
margin:200px auto;
}
#select-item{
position: absolute;
bottom:0;
left:50%;
margin-left:-75px;
}
#select-item .select{
background-color: orange;
}
#select-item li{
float:left;
width:20px;
height:20px;
line-height:20px;
text-align: center;
background-color: #ccc;
border-radius:50%;
margin-right:5px;
cursor:pointer;
}
#pre,#next{
position:absolute;
display:none;
color:#fff;
width:28px;
height:62px;
font-size:20px;
line-height:62px;
text-align: center;
font-weight:400;
background-color:rgba(0,0,0,.2);
top:50%;
margin-top:-31px;
cursor:pointer;
}
#pre{
left:0;
}
#next{
right:0;
}
#mask{
position:absolute;
width:730px;
height:454px;
background-color: #ccc;
line-height: 454px;
text-align: center;
z-index:1;
opacity:0.8;
filter:alpha(opacity = 80);
font-size:20px;
font-weight:bold;
}
</style>
</head>
<body>
<div id="container">
<div id="mask">加载中...</div>
<div id="imgs"></div>
<ul id="select-item"></ul>
<div id="select-mov">
<span id="pre"><</span>
<span id="next">></span>
</div>
</div>
<script>
var oImgs = getElemById("imgs");
var aImgs = getElemsByTagName(oImgs,"img");
var oSelectItem = getElemById("select-item");
var aItemLi = getElemsByTagName(oSelectItem,"li");
var oPre = getElemById("pre");
var oNext = getElemById("next");
var oMask = getElemById("mask");
var oContainer = getElemById("container");
var nowIdx = 0
var imgNum = 6;
var count = 0;
oSelectItem.style.marginLeft = -(imgNum * 25/2) + "px";
for(var i = 0; i < imgNum; i++){
var oLi = document.createElement("li");
oLi.innerHTML = i + 1;
oSelectItem.appendChild(oLi);
var oImg = new Image();
oImg.onload = function(){
count++;
if(count == imgNum){
loadSucessful();
}
}
oImg.src = "img/" + (i + 1) + ".jpg";
oImgs.appendChild(oImg);
}
function loadSucessful(){
oContainer.removeChild(oMask);
changeImg(nowIdx);
for(var i = 0; i < imgNum; i++){
aItemLi[i].index = i;
aItemLi[i].onmouseover = function(){
changeImg(this.index);
}
}
}
oPre.onclick = oNext.onclick = function(){
if(this == oPre){
nowIdx--;
if(nowIdx == -1){
nowIdx = aItemLi.length - 1;
}
}else{
nowIdx++;
if(nowIdx == aItemLi.length){
nowIdx = 0;
}
}
changeImg(nowIdx);
}
var timer = setInterval(function(){
oNext.onclick();
},1000);
oContainer.onmouseover = function(){
clearInterval(timer);
oPre.style.display = "inline-block";
oNext.style.display = "inline-block";
}
oContainer.onmouseout = function(){
clearInterval(timer);
timer = setInterval(function(){
oNext.onclick();
},1000);
oPre.style.display = "none";
oNext.style.display = "none";
}
function changeImg(idx){
nowIdx = idx;
for(var j = 0; j < aItemLi.length; j++){
aItemLi[j].style.backgroundColor = "#ccc";
aImgs[j].style.display = "none";
}
aItemLi[idx].style.backgroundColor = "orange";
aImgs[idx].style.display = "block";
}
function getElemById(id){
return document.getElementById(id);
}
function getElemsByTagName(obj,name){
return obj.getElementsByTagName(name);
}
</script>
</body>
</html>