首页 > 代码库 > js-小效果-无缝滚动

js-小效果-无缝滚动

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding:0;
list-style: none;
}
#box{
width:1102px;
position:relative;
height:152px;
overflow: hidden;
border:1px solid #000;
margin: 50px auto;
}
#ul{
position: absolute;
left:0;
top:0;
}
#ul li{
width:200px;
height:150px;
float:left;
padding:0 10px;}
#ul li img{
width:200px;
height:150px;
}
</style>
<script>
window.onload=function(){
var oBox=document.getElementById(‘box‘);
var oUl=document.getElementById(‘ul‘);
var aLi=oUl.children;
oUl.innerHTML+=oUl.innerHTML;
oUl.style.width=aLi.length*aLi[0].offsetWidth+‘px‘;
setInterval(function(){
var l=oUl.offsetLeft-5;
if(l<=-oUl.offsetWidth/2){
l=0;
}
oUl.style.left=l+‘px‘;
},30)
}
</script>
</head>
<body>
<div id="box">
<ul id="ul">
<li><img src="http://www.mamicode.com/img/banner1.jpg" /></li>
<li><img src="http://www.mamicode.com/img/banner2.jpg" /></li>
<li><img src="http://www.mamicode.com/img/banner3.jpg" /></li>
<li><img src="http://www.mamicode.com/img/banner4.jpg" /></li>
<li><img src="http://www.mamicode.com/img/banner5.jpg" /></li>
</ul>
</div>
</body>
</html>

js-小效果-无缝滚动