网页图片轮播

来源:互联网 发布:ui界面设计用什么软件 编辑:程序博客网 时间:2024/05/08 07:55
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#spanbtn span{
display:inline-block;
width:18px;
height:18px;
border:#fff 1px solid;
text-align:center;
margin-right:2px;
}
#spanbtn span:hover{color:#f00;}
</style>
<script >
function showobj(id)
{
var obj=document.getElementById(id);
obj.style.display="";
}
function hiddenobj(id)
{
var obj =document.getElementById(id);
obj.style.display="none";
}
var arr=new Array;
arr[0]="1.jpg";
arr[1]="2.jpg";
arr[2]="3.jpg";
arr[3]="4.jpg";
var count=0;
function autoPlayer()
{
if(arr.length==count)
count=0;
document.getElementById("banner").src=arr[count];
count++;
}
var Timer=setInterval(autoPlayer,2000);
//清除定时器对象
function clearTimer()
{
clearInterval(Timer);
}
//鼠标悬停时指定播放的图片
function showbannerbyid(num)
{
clearTimer();
var index=parseInt(num);
document.getElementById("banner").src=arr[index-1];
count=index;
}
//鼠标离开恢复自动播放效果
function btnMouseOut()
{
Timer=setInterval(autoPlayer,2000);
}
</script>
</head>
<body>


<div id="bannerbox"   style="position:relative">
<div>
<img id="banner" width="500px" src="1.jpg"/>
</div>
<div id="spanbtn" style="position:absolute; right:800px;bottom:10px;">
<span onmouseover="showbannerbyid(1)" onmouseout="btnMouseOut()">1</span>
<span onmouseover="showbannerbyid(2)" onmouseout="btnMouseOut()">2</span>
<span onmouseover="showbannerbyid(3)" onmouseout="btnMouseOut()">3</span>
<span onmouseover="showbannerbyid(4)" onmouseout="btnMouseOut()">4</span>
</div>
</div>
</body>
</html>
1 0