<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图片向左无缝滚动</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#area {
width:600px;
height: 200px;
border: 1px solid #ccc;
margin-left: 200px;
margin-top:100px;
overflow: hidden;
}
#box1{
width: 800px;
}
#area ul li{
float: left;
list-style: none;
width: 200px;
}
</style>
</head>
<body>
<div id="area">
<ul id="box1">
<li><i><img src="images/1.jpg" alt="头像"></i></li>
<li><i><img src="images/2.jpg" alt="头像"></i></li>
<li><i><img src="images/3.jpg" alt="头像"></i></li>
<li><i><img src="images/4.jpg" alt="头像"></i></li>
<li><i><img src="images/5.jpg" alt="头像"></i></li>
<li><i><img src="images/6.jpg" alt="头像"></i></li>
</ul>
<ul id="box2"></ul>
</div>
<script type="text/javascript">
window.onload=function(){
var area=document.getElementById('area');
var box1=document.getElementById('box1');
var box2=document.getElementById('box2');
var time=50;
var timer=setInterval('move()',time);
box2.innerHTML=box1.innerHTML;
area.onmouseover=function(){
clearInterval(timer);
}
area.onmouseout=function(){
timer=setInterval('move()',time);
}
}
function move(){
if(box1.scrollLeft>=area.offsetWidth){
box1.scrollLeft=0;
}else{
box1.scrollLeft++;
}
}
</script>
</body>
</html>