<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>无缝滚动</title>
<style>
*{
margin:0;
padding: 0;
}
ul{
list-style: none;
}
img{
vertical-align: top;
}
.box{
width: 600px;
height: 200px;
background-color: red;
margin:100px auto;
position: relative;
overflow:hidden;
}
.box ul li{
float: left;
}
.box ul{
width: 400%;
position: absolute;
left: 0;
top: 0;
}
</style>
</head>
<body>
<div id="dome">
<ul>
<li><img src="./images/01.jpg"></li>
<li><img src="./images/02.jpg"></li>
<li><img src="./images/03.jpg"></li>
<li><img src="./images/04.jpg"></li>
<li><img src="./images/01.jpg"></li>
<li><img src="./images/02.jpg"></li>
</ul>
</div>
<script>
var dome = document.getElementById("dome");
var ul = dome.children[0];
var num = 0;
setInterval(fun,1);
function fun(){
num--;
if(num >= -1200 ){
ul.style.left = num + "px";
}
else{
ul.style.left = 0;
num = 0; //这里为什么不是num--。让left重新走动呢
}
}
</script>
</body>
</html>
发卡君
相关分类