-
Notifications
You must be signed in to change notification settings - Fork 0
/
move7.html
289 lines (280 loc) · 7.68 KB
/
move7.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>运动7</title>
<style type="text/css">
* {
margin:0;
padding:0;
}
body {
background:rgb(55, 55, 120);;
}
.container {
width: 800px;
margin: 10px auto;
background: rgb(243, 255, 205);
position: relative;
padding-bottom: 1px;
}
.container .big {
position: relative;
overflow: hidden;
width: 800px;
height: 500px;
}
.container .small {
position: relative;
overflow: hidden;
width: 790px;
height: 140px;
margin: 10px auto 10px;
}
.container .big .bigPictures {
position: relative;
z-index: 1;
}
.container .small .smallPictures {
position: relative;
}
.container .big .left {
width: 400px;
height: 500px;
position: absolute;
left: 0;
top: 0;
z-index: 3000;
}
.container .big .left img {
width: 100px;
position: relative;
left: 10px;
top: 200px;
opacity: 0;
filter: alpha(opacity:0);
}
.container .big .right {
width: 400px;
height: 500px;
position: absolute;
right: 0;
top: 0;
z-index: 3000;
}
.container .big .right img {
width: 100px;
position: relative;
left: 290px;
top: 200px;
opacity: 0;
filter: alpha(opacity:0);
}
ul li {
list-style-type: none;
float: left;
}
.smallPictures li {
margin: 0 5px;
opacity: 0.6;
filter: alpha(opacity:60);
}
.bigPictures img {
width: 800px;
height: 500px;
}
.smallPictures img {
width: 253px;
height: auto;
}
</style>
<script>
function getByClass(name){
var aResult=[];
var aObj=document.getElementsByTagName('*');
for(var i=0;i<aObj.length;i++){
if(aObj[i].className==name){
aResult.push(aObj[i]);
}
}
return aResult;
}
window.onload=function (){
var oCon=getByClass('container')[0];
var oLeft=getByClass('left')[0];
var oRight=getByClass('right')[0];
var oPreview=getByClass('preview')[0];
var oNext=getByClass('next')[0];
var oSmall=getByClass('smallPictures')[0];
var aSmallLi=oSmall.getElementsByTagName('li');
var oBig=getByClass('bigPictures')[0];
var aBigLi=oBig.getElementsByTagName('li');
var aBigImg=oBig.getElementsByTagName('img');
var aSmallImg=oSmall.getElementsByTagName('img');
var now=0;
// function 1: Show the preview and next button when move the mouse over and out;
oLeft.onmouseover=function (){
move(oPreview, 'opacity', 100);
};
oLeft.onmouseout=function (){
move(oPreview, 'opacity', 0);
};
oRight.onmouseover=function (){
move(oNext, 'opacity', 100);
};
oRight.onmouseout=function (){
move(oNext, 'opacity', 0);
}
// function 2: Change the view of the big pictures when click the small pictures:
oBig.style.height=aBigLi.length*aBigImg[0].offsetHeight+'px';
oSmall.style.width=aSmallLi.length*(aSmallImg[0].offsetWidth+10)+'px';
function tab(){
var s=-now*(aBigImg[0].offsetHeight+5);
move(oBig, 'top', s);
// function 3: Scroll the small pictures whice is choosen to the center:
if(now==1||now==0){
move(oSmall, 'left', 0);
}
else if (now==aSmallLi.length-1){
var t1=-(now-2)*(aSmallImg[0].offsetWidth+10);
move(oSmall, 'left', t1);
}
else {
var t2=-(now-1)*(aSmallImg[0].offsetWidth+10);
move(oSmall, 'left', t2);
}
}
for(var i=0;i<aSmallLi.length;i++){
aSmallLi[i].index=i;
aSmallLi[i].onclick=function (){
now=this.index;
tab();
}
}
// function 4: Use the preview and next bottom to control the progress:
oLeft.onclick=function (){
if(now==0){
now=aSmallLi.length-1;
tab();
}
else {
now--;
tab();
}
for(var i=0;i<aSmallLi.length;i++){
//move(aSmallLi[i], 'opacity', '0.6');
aSmallLi[i].style.opacity=0.6;
};
//move(aSmallLi[now], 'opacity', '1');
aSmallLi[now].style.opacity=1;
};
oRight.onclick=function (){
if(now==aSmallLi.length-1){
now=0;
tab();
}
else {
now++;
tab();
}
for(var i=0;i<aSmallLi.length;i++){
aSmallLi[i].style.opacity=0.6;
};
aSmallLi[now].style.opacity=1;
};
// function 5: Change the opacity of the small images when it is chosen:
for(var i=0;i<aSmallLi.length;i++){
aSmallLi[i].index=i;
aSmallLi[i].onmouseover=function (){
for(var i=0;i<aSmallLi.length;i++){
aSmallLi[i].style.opacity=0.6;
}
aSmallLi[this.index].style.opacity=1;
}
aSmallLi[i].onmouseout=function (){
if(this.index==now){
aSmallLi[now].style.opacity=1;
}
else {
aSmallLi[now].style.opacity=1;
aSmallLi[this.index].style.opacity=0.6;
}
}
}
// function 6: Auto play:
var timer=null;
timer=setInterval(oRight.onclick, 4000);
oCon.onmouseover=function (){
clearInterval(timer);
}
oCon.onmouseout=function (){
timer=setInterval(oRight.onclick, 4000);
};
}
function getStyle(obj, attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}
else {
return getComputedStyle(obj, false)[attr];
}
}
function move(obj, attr, target){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var cur=0;
if (attr=='opacity') {
cur=Math.round(parseFloat(getStyle(obj, attr))*100);
}
else {
cur=parseInt(getStyle(obj, attr)); // Attention: if without parseInt(), something would go wrong with the function!
}
var speed=(target-cur)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if (target==cur) {
clearInterval(obj.timer);
}
else {
if(attr=='opacity'){
obj.style.filter='alpha(opacity:'+(cur+speed)+')' ;
obj.style.opacity=(cur+speed)/100; // Attention: Used in the modern brower, we should divide it by 100;
}
else {
obj.style[attr]=cur+speed+'px';
}
}
},30)
}
</script>
</head>
<body>
<div class="container">
<div class="big">
<div class="left">
<a href='javascript:;'><img class='preview' src="img/left.jpg" /></a>
</div>
<div class="right">
<a href='javascript:;'><img class='next' src="img/right.jpg" /></a>
</div>
<ul class="bigPictures">
<li><img src="img/1.jpg" /></li>
<li><img src="img/2.jpg" /></li>
<li><img src="img/3.jpg" /></li>
<li><img src="img/4.jpg" /></li>
<li><img src="img/5.jpg" /></li>
<li><img src="img/6.jpg" /></li>
</ul>
</div>
<div class="small">
<ul class="smallPictures">
<li style="opacity:1; "><a href='javascript:;'><img src="img/1.jpg" /></a></li>
<li><a href='javascript:;'><img src="img/2.jpg" /></a></li>
<li><a href='javascript:;'><img src="img/3.jpg" /></a></li>
<li><a href='javascript:;'><img src="img/4.jpg" /></a></li>
<li><a href='javascript:;'><img src="img/5.jpg" /></a></li>
<li><a href='javascript:;'><img src="img/6.jpg" /></a></li>
</ul>
</div>
</div>
</body>
</html>