-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path自动幻灯片效果.html
168 lines (157 loc) · 3.03 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>untitled</title>
<style>
body,div,ul,li{margin:0;padding:0;}
ul{
list-style-type:none;
}
body{
background:#000;
text-align:center;
font:12px/20px Arial;
}
#box{
position:relative;
width:492px;
height:172px;
background:#fff; /*用背景颜色和图片塑造边框的效果*/
border-radius:5px;
border:8px solid #fff;
margin:10px auto;
}
#box .list{
position:relative;
width:490px;
height:170px;
overflow:hidden;
border:1px solid #ccc;
}
#box .list li{
position:absolute;
top:0;
left:0;
width:490px;
height:170px;
opacity:0;
filter:alpha(opacity=0);
}
#box .list li.current{
opacity:1;
filter:alpha(opacity=100);
}
#box .count{
position:absolute;
right:0;
bottom:5px;
}
#box .count li{
color:#fff;
float:left;
width:20px;
height:20px;
cursor:pointer;
margin-right:5px;
overflow:hidden;
background:#f90;
opacity:0.7;
filter:alpha(opacity=70);
border-radius:20px;
}
#box .count li.current{
color:#fff;
filter:alpha(opacity=100);
font-weight:700;
background:#f60;
}
#tmp{
width:100px;
height:100px;
background:red;
position:absolute;
}
</style>
<script>
window.onload=function()
{
var oBox=document.getElementById("box");
var aUl=document.getElementsByTagName("ul");
var aImg=aUl[0].getElementsByTagName("li");
var aNum=aUl[1].getElementsByTagName("li");
var timer=play=null;
var i=index=0;
//切换按钮
for(var i=0;i<aNum.length;i++)
{
aNum[i].index=i;
aNum[i].onmouseover=function()
{
show(this.index);
}
}
//鼠标划过关闭计时器
oBox.onmouseover=function()
{
clearInterval(play);
}
//鼠标离开启动自动播放
oBox.onmouseout=function()
{
autoPlay();
}
//自动播放函数
function autoPlay()
{
play=setInterval(function(){
index++;
index>=aImg.length && (index=0);
//这句话的意思是if(index>=aImg.length){index=0;}
show(index);
},2000);
}
autoPlay();//随时实现
//图片切换,淡入淡出
function show(a)
{
index=a;
var alpha=0;
for(i=0;i<aNum.length;i++)aNum[i].className="";
aNum[index].className="current";
clearInterval(timer);
for(i=0;i<aImg.length;i++)
{
aImg[i].style.opacity=0;
aImg[i].style.filter="alpha(opacity=0)";
}
timer=setInterval(function(){
alpha+=2;
alpha>100 && (alpha=100);
aImg[index].style.opacity=alpha/100;
aImg[index].style.filter="alpha(opacity="+alpha+")";
alpha==100 && clearInterval(timer);
},20);
}
}
</script>
</head>
<body>
<div id="box">
<ul class="list">
<li class="current"><img src="image2/049.jpg" width="490" height="170"/></li>
<li><img src="image2/053.jpg" width="490px" height="170" /></li>
<li><img src="image2/057.jpg" width="490px" height="170" /></li>
<li><img src="image2/059.jpg" width="490px" height="170" /></li>
<li><img src="image2/052.jpg" width="490px" height="170" /></li>
</ul>
<ul class="count">
<li class="current">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</body>
</html>