代码如下:
<!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>
*{padding:0; margin:0;}
#div1 {width:712px; height:108px; position:relative; margin:100px auto; overflow:hidden;}
#div1 ul{ position:absolute; left:0; top:0; }
#div1 ul li{ float:left; list-style:none; }
#div1 ul li img{width:178px; height:108px;width:178px; height:108px; }
</style>
<script>
window.onload=function(){
var oBate=document.getElementById('div1');
var oUl=oBate.getElementsByTagName('ul')[0];
var oLi=oUl.getElementsByTagName('li');
var speed=2;
oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;
oUl.style.width=oLi[0].offsetWidth*oLi.length+'px';
function move()
{
if(oUl.offsetLeft< -oUl.offsetWidth/2)
{
oUl.style.left='0';
}
if(oUl.offsetLeft>0)
{
oUl.style.left=-oUl.offsetWidth/2+'px';
}
oUl.style.left=oUl.offsetLeft-speed+'px';
}
var timer=setInterval( move,30);
oBate.onmouseover=function()
{
clearInterval(timer);
};
oBate.onmouseout=function()
{
timer=setInterval(move,30);
};
document.getElementsByTagName('a')[0].onclick=function()
{
speed=2;
}
document.getElementsByTagName('a')[1].onclick=function()
{
speed=-2;
}
};
</script>
</head>
<!--向左,向右调节滚动的方向-->
<body>
<a href="javascript:;">向左</a>
<a href="javascript:;">向右</a>
<div id="div1">
<ul>
<li><img src="img1/1.jpg" /></li>
<li><img src="img1/2.jpg" /></li>
<li><img src="img1/3.jpg" /></li>
<li><img src="img1/4.jpg" /></li>
</ul>
</div>
</body>
</html>