主要代码:
<!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>
* {margin:0;padding:0;}
#div1{width:480px;height:80px;position:relative;margin:70px auto;background:blue; overflow:hidden;}
#div1 ul{position:absolute;left:0;top:0;}
#div1 ul li{float:left;width:120px;height:80px;list-style:none;}
</style>
<script>
window.onload=function(){
var oDiv=document.getElementById('div1');
var oUl=oDiv.getElementsByTagName('ul')[0];
var oLi=oUl.getElementsByTagName('li');
oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;
oUl.style.width=oLi[0].offsetWidth*oLi.length+'px';
setInterval(function(){
if(oUl.offsetLeft<-oUl.offsetWidth/2){
oUl.style.left='0';
}
oUl.style.left=oUl.offsetLeft-2+'px';
},30);
}
</script>
</head>