HTML代码
<div id="controls">
<input id="round" type="button" value = "循环播放">
<input id="single" type="button" value = "顺序播放">
</div>
<div id="container">
<a href='javascript:' id="prev"><</a>
<a href='javascript:' id="next">></a>
<div id="order">图片加载中……
</div>
<div id="info">图片加载中……
</div>
<img id="picture">
</div>
CSS代码
<style>
#controls {
width:400px
;
margin: auto
;
text-align: center
;
}
#container {
width: 400px
;
height:400px
;
border: 10px solid #eee
;
position: relative
;
background: gray
;
margin: 10px auto 0
;
}
#prev, #next {
position: absolute
;
background: black
;
filter:alpha(opacity:40
);
opacity: 0.4
;
font-size: 20px
;
color: white
;
width: 40px
;
height: 40px
;
border: 2px solid white
;
line-height: 40px
;
text-align: center
;
top: 180px
;
text-decoration: none
;
}
#prev:hover, #next:hover {
filter: alpha(opacity:a80
);
opacity:0.8
;
}
#order, #info {
position: absolute
;
width:100%
;
height: 30px
;
line-height: 30px
;
text-align: center
;
background: black
;
filter:alpha(opacity:60
);
opacity: 0.6
;
font-size: 20px
;
color: white
;
}
#prev {
left: 0
;
}
#next {
right: 0
;
}
#picture {
height: 400px
;
width: 400px
;
}
#order {
top: 0
;
}
#info {
bottom: 0
;
}
</style>
JS代码
<script
>
function $id(id
){
return document
.getElementById(id
);
}
var arrImg
= ['./6.jpg','./7.jpg','./8.jpg','./9.jpg'];
var arrText
= ['图片一','图片二','图片三','图片四'];
var index
= 0;
var shunxu
= true;
function pic(){
$id("picture").src
= arrImg
[index
];
$id("order").innerHTML
= (index
+1)+"/"+4;
$id("info").innerHTML
= arrText
[index
];
}
pic();
$id("next").onclick = function(){
index
++;
if(shunxu
&& index
==arrImg
.length
){
alert("已经是最后一张了");
index
--;
}
else if(!shunxu
&& index
==arrImg
.length
){
index
= 0;
}
pic();
}
$id("prev").onclick = function(){
index
--;
if(shunxu
&&index
==-1){
alert("已经是第一张了")
index
= 0;
}
else if(!shunxu
&& index
==-1){
index
= arrImg
.length
-1
}
pic();
}
$id("round").onclick = function(){
shunxu
= false;
}
$id("single").onclick = function(){
shunxu
= true;
}
</script
>
转载请注明原文地址:https://tech.qufami.com/read-1632.html