-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path自动播放_幻灯片缓冲.html
150 lines (133 loc) · 3.43 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
<!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;cursor:pointer;}
#box .list{position:relative;width:490px;height:170px;overflow:hidden;}
#box .list ul{position:absolute;top:0;left:0;}
#box .list li{width:490px;height:170px;overflow:hidden;}
#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:#f60;
opacity:0.7;
filter:alpha(opcity=70);
border-radius:20px;
}
#box .count li.current{
color:#fff;
opacity:1;
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 oList=oBox.getElementsByTagName("ul")[0];
var aImg=oBox.getElementsByTagName("img");
var timer=playTimer=null;
var index=i=0;
var bOrder=true;
var aTmp=[];
var aBtn=null;
//生成数字按钮
for(i=0;i<aImg.length;i++) aTmp.push("<li>"+(i+1)+"</li>");
//插入元素
var oCount=document.createElement("ul");
oCount.className="count";
oCount.innerHTML=aTmp.join("");
oBox.appendChild(oCount);
aBtn=oBox.getElementsByTagName("ul")[1].getElementsByTagName("li");
//初始化状态
/* */
cutover();
//按钮点击切换
for(i=0;i<aBtn.length;i++)
{
aBtn[i].index=i;
/*依次给list中的index赋值*/
aBtn[i].onmouseover=function()
{
index=this.index;
/*将list中index的值原原本本地赋值给index变量方便cutover调用*/
cutover();
}
}
//自动播放函数的实现(切换图片)
function cutover()
{
for(i=0;i<aBtn.length;i++)aBtn[i].className="";
aBtn[index].className="current";
startMove(-(index*aImg[0].offsetHeight));
}
//next自动播放函数的控制
function next()
{
bOrder?index++:index--;
index<=0 && (index=0,bOrder=true);
index>=aBtn.length-1 && (index=aBtn.length-1,bOrder=false);
cutover();
}
//鼠标移入展示区后停止自动播放
oBox.onmouseover=function()
{
clearInterval(playTimer);
};
//鼠标离开后展示区自动播放,触发next函数实现自动播放
oBox.onmouseout=function()
{
playTimer=setInterval(next,3000);
};
//开始的时候默认开启
playTimer=setInterval(next,3000);
//图片切换真正实现的地方
function startMove(iTarget)
{
clearInterval(timer);
timer=setInterval(function(){
doMove(iTarget);
},30);
}
function doMove(iTarget)
{
var iSpeed=(iTarget-oList.offsetTop)/10;
iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);
oList.offsetTop==iTarget?clearInterval(timer):oList.style.top=oList.offsetTop+iSpeed+"px";
}
}
</script>
</head>
<body>
<div id="box">
<div class="list">
<ul>
<li><img src="image2/066.jpg" width="490" height="170" /></li>
<li><img src="image2/065.jpg" width="490" height="170" /></li>
<li><img src="image2/058.jpg" width="490" height="170" /></li>
<li><img src="image2/055.jpg" width="490" height="170" /></li>
<li><img src="image2/019.jpg" width="490" height="170" /></li>
</ul>
</div>
</div>
</body>
</html>