-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_上下轮播.html
154 lines (135 loc) · 3.03 KB
/
my_上下轮播.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
body,div,ul,li{
margin:0;
padding:0;
list-style: none;
border: 0;
}
body{
background: #000;
}
#box{
width: 502px;
height: 202px;
margin:10px auto;
border: 8px solid #002232;
position: relative;
overflow: hidden;
}
#box .list-image{
/*border: 1px solid purple;*/
width: 500px;
height: 200px;
position: absolute;
}
#box .list-image li{
border: 1px solid purple;
width: 500px;
height: 200px;
}
#box .list-number{
z-index: 999;
position: absolute;
right: 0;
bottom: 5px;
}
#box .list-number li{
color: #fff;
float: left;
width: 20px;
height: 20px;
background: #f60;
border-radius: 20px;
font:12px/20px Arial;
/*这里有个要点*/
margin-right: 10px;
cursor: pointer;
text-align: center;
opacity: 0.7;
filter: alpha(opacity=70);
}
#box .list-number li.current{
opacity: 1;
filter: alpha(opacity=100);
}
</style>
</head>
<body>
<div id="box">
<ul class="list-image">
<li><img src="../image/landscape_map/047.jpg" width="500px" height="200px"></li>
<li><img src="../image/landscape_map/041.jpg" width="500px" height="200px"></li>
<li><img src="../image/landscape_map/042.jpg" width="500px" height="200px"></li>
<li><img src="../image/landscape_map/043.jpg" width="500px" height="200px"></li>
<li><img src="../image/landscape_map/037.jpg" width="500px" height="200px"></li>
</ul>
</div>
</body>
<script>
var oBox=document.getElementById("box");
var oUl=oBox.getElementsByTagName("ul");
var oImage=oUl[0].getElementsByTagName("li");
//创建数组元素
var tmp=[];
for(var i=0;i<oImage.length;i++){
tmp.push("<li>"+(i+1)+"</li>");
}
//现在tmp中保存着五个<li>
var oCount=document.createElement("ul");
oCount.className="list-number";
oCount.innerHTML=tmp.join('');
oBox.appendChild(oCount);
var index=0;
oNumber=oCount.getElementsByTagName("li");
for(var i=0;i<oNumber.length;i++){
oNumber[i].index=i;
oNumber[i].onmouseover=function(){
show(this.index);
}
}
function show(x){
for(var i=0;i<oNumber.length;i++)
{
oNumber[i].className="";
}
oNumber[x].className="current";
Move(x);
}
var timer=null;
function Move(x){
clearInterval(timer);
//赋值的时候要加上"px"哦
target=-x*202;
timer=setInterval(function(){
var speed=(-x*202-oUl[0].offsetTop)/10;
//因为是当前值,所有这个speed可正可负,根据我们所处图片的位置和要切换的目的地不同而定
speed=speed>0?Math.ceil(speed):Math.floor(speed);
oUl[0].offsetTop==target?clearInterval(timer):oUl[0].style.top=oUl[0].offsetTop+speed+"px";
},30)
index=x;//为了bug:若是我们先按了3,再来开进行自动轮播,它是从上一次index记录的开始自动。
}
var autotimer=null;
oBox.onmouseout=function(){
auto();
}
oBox.onmouseover=function(){
clearInterval(autotimer);
}
function auto(){
autotimer=setInterval(function(){
if(index<oImage.length-1){
index++;
}else{
index=0;
}
show(index);
},2000)
}
auto();
</script>
</html>